I am trying to create an HTML button that allows the user to select an option to submit. My code does indeed create a button with an embedded drop-down menu, but when the user tries to select a particular option, the button executes immediately. Thus it does not matter which option is selected; it always executes the default option.
I have searched many websites to try to grasp this seemingly simple concept to no avail. Here is my code:
<button class="btn btn-primary btn-sm" id="action">Action <select name="options"> <option value="">Select</option> <option value="one">One</option> <option value="two">Two</option> </select> </button>
I did not make it clear that I am using js to retrieve the value. I have therefore changed the code slightly but it still executes using the button, AS WELL AS by using the select element. I want only the button to execute by sending the value of the option chosen.
I am also not clear on what is actually being submitted. I thought that the
id element would be submitted as an array and then I could access the data I need using
document.getElementById("action"). The names, labels, values, options, and ids, confuse me. What am I missing?