When I'm disabling a
<select name="sel" disabled> <option>123</option> </select>
element, it doesnt pass its variable.
What to do to look it like disabled, but be in "normal" state?
This is because I have a list of "selects", and sometimes some of them have single value, so user should understand that it has only one value without clicking it.
The disabled attribute for <select> element in HTML is used to specify that the select element is disabled. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute.
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 drop-down is used to create a list of items that need to select an element. We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element.
The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable. Tip: Disabled <input> elements in a form will not be submitted!
You can keep it disabled as desired, and then remove the disabled attribute before the form is submitted.
$('#myForm').submit(function() { $('select').removeAttr('disabled'); });
Note that if you rely on this method, you'll want to disable it programmatically as well, because if JS is disabled or not supported, you'll be stuck with the disabled select.
$(document).ready(function() { $('select').attr('disabled', 'disabled'); });
<select id="test" name="sel"> <option disabled>1</option> <option disabled>2</option> </select>
or you can use jQuery
$("#test option:not(:selected)").prop("disabled", true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With