Skip to content
Advertisement

How to disable a submit button until a radio button is selected (Javascript, HTML, and Flask)

I’ve seen other questions similar to this one, but I don’t know if my application isn’t working because I’m using a Flask/SQLAlchemy application (a truck scheduling application) or if there’s something else I’m missing. I want to disable the submit/update button until the user selects one of the materials to be picked up.

update.html:

JavaScript

Advertisement

Answer

.getElementsByName() returns a node list and doesn’t support .addEventListener(), however the elements in that node list do.

Also, the Boolean false is false in JavaScript, not False.

Instead of attaching an event listener to each of the radio buttons, you can attach the listener to a common ancestor of them, in this case the form. Then, when the listener fires, you can check to see if it was one of the radio buttons that initiated the event and, if so, act.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement