[Solved- 4 Answers] how to set select element as readonly
According to HTML specs, the select tag in HTML doesn’t have a read only attribute, only a disabled attribute. So if you want to keep the user from changing the drop down, 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 read only attribute for a select tag, and still get the POST data?
You should keep the select element disabled but also add another hidden input 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.
Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.
Thanks it was helpful.