Javascript examples for DOM HTML Element:Option
The disabled property sets or gets whether an option in a drop-down list should be disabled.
Set the disabled property with the following Values
Value | Description |
---|---|
true|false | Sets whether an option in a drop-down list should be disabled |
A Boolean, returns true if the option is disabled, otherwise it returns false
The following code shows how to Disable the third option (index 2) in a drop-down list:
<!DOCTYPE html> <html> <body> <select id="pets" size="3"> <option>Cat</option> <option>Dog</option> <option>Horse</option> </select>/*from w ww . j a v a2s . c o m*/ <button onclick="myFunction()">Disable Option</button> <script> function myFunction() { var x = document.getElementById("pets").options[2].disabled = true; } </script> </body> </html>