I have a select
form field that I want to mark as "readonly", as in the user cannot modify the value, but the value is still submitted with the form. Using the disabled
attribute prevents the user from changing the value, but does not submit the value with the form.
The readonly
attribute is only available for input
and textarea
fields, but that's basically what I want. Is there any way to get that working?
Two possibilities I'm considering include:
- Instead of disabling the
select
, disable all of theoption
s and use CSS to gray out the select so it looks like its disabled. - Add a click event handler to the submit button so that it enables all of the disabled dropdown menus before submitting the form.
I was faced with a slightly different scenario, in that I only wanted to not allow the user to change the selected value based on an earlier selectbox. What I ended up doing was just disabling all the other non-selected options in the selectbox using
Another option is to use the readonly attribute.
With readonly the value is still submitted, the input field is grayed out and the user cannot edit it.
Edit:
Quoted from http://www.w3.org/TR/html401/interact/forms.html#adef-readonly:
When it says the element may be succesful, it means it may be submitted, as stated here: http://www.w3.org/TR/html401/interact/forms.html#successful-controls
Or use some JavaScript to change the name of the select and set it to disabled. This way the select is still submitted, but using a name you aren't checking.
I`ve been looking for a solution for this, and since i didnt find a solution in this thread i did my own.
Simple, you just blur the field when you focus on it, something like disabling it, but you actually send its data.
The easiest way i found was to create a tiny javascript function tied to your form :
and you call it in your form here :
Or you can call it in the function you use to check your form :)
it dows not work with the :input selector for select fields, use this: