According to HTML specs, the select
tag in HTML doesn't have a readonly
attribute, only a disabled
attribute. So if you want to keep the user from changing the dropdown, you have to use disabled
.
The only problem is that disabled HTML form inputs don't get included in the POST / GET data.
What's the best way to emulate the readonly
attribute for a select
tag, and still get the POST data?
I resolved it with jquery:
You should keep the
select
elementdisabled
but also add another hiddeninput
with the same name and value.If you reenable your SELECT, you should copy its value to the hidden input in an onchange event and disable (or remove) the hidden input.
Here is a demo:
another way of doing a
readOnly
attribute to aselect
element is by usingcss
you could do like :
DEMO
html solution:
javascript ones:
to remove:
edit: added remove methods
Below worked for me :
Following on from Grant Wagners suggestion; here is a jQuery snippet that does it with handler functions instead of direct onXXX attributes: