Lock HTML select element, allow value to be sent on submit

Posted by ILMV on Stack Overflow See other posts from Stack Overflow or by ILMV
Published on 2010-04-08T13:19:01Z Indexed on 2010/04/08 13:23 UTC
Read the original article Hit count: 265

Filed under:
|
|

I have a select box (for a customer field) on a complex order form, when the user starts to add lines to the order they should not be allowed to change the customer select box (unless all lines are deleted).

My immediate thought was that I could use the disabled attribute, but when the box is disabled the selected value is no longer passed to the target.

When the problem arose a while ago one of the other developers worked around this by looping through all the options and disabling all but the selected option, and sure enough the value was passed to the target and we've been using since. But now I'm looking for a proper solution, I don't want to loop through all the options because are data is expanding and it's starting to introduce performance issues.

I'd prefer not to enable this / all the elements when the submit button is hit.

How can I lock the input, whilst maintaining the selected option and passing that value to the target script? I would prefer a non-JavaScript solution if possible, but if needed we are running jQuery 1.4.2 so that could be used.

© Stack Overflow or respective owner

Related posts about html

Related posts about select