Categories
HTML

How to ensure a select form field is submitted when it is disabled with HTML?

Spread the love

To ensure a select form field is submitted when it is disabled with HTML, we set the name of a hidden input to the same name as the disabled select element.

For instance, we write

<select name="myselect" disabled="disabled">
  <option value="myselectedvalue" selected="selected">My Value</option>
  ....
</select>
<input type="hidden" name="myselect" value="myselectedvalue" />

to add a select and a hidden input element.

We set the name attribute of both elements to myselect.

And then the value of the hidden input will be submitted to the server.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *