How to Make a dropdown readonly using Jquery09 Oct 2016
Dropdown (select element) is always read only. User do not edit it. User can select any of the option of its own chice. Unlike other html elements, it dont have a attribute which can make the element readony and prevent users to change its value.
So how do we do this, when we want to prevent the user not to edit its selected option.
There is a little trick. Why can’t we disable it.
Wait a second…
But as we are disabling this field, the field will not be the part of the request when the form is submitted.
We can do some work around for this.
So we need to use a hidden field to store disabled selected-option value. When the moment select element is disabled we need to create a hidden input field in the form and store the selected value. The moment it is enabled we need to restore the element with the value stored in the hidden field.
Here you go with a code example -
Here is a live example.