Disable a drop-down list:
document.getElementById("mySelect").disabled = true;
Click the button to disable the dropdown list.
<!DOCTYPE html> <html> <body> <form> <select id="mySelect"> <option>Cats</option> <option>Dogs</option> </select> </form>//from w ww. ja v a2s . c o m <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("mySelect").disabled = true; } </script> </body> </html>
The disabled property sets or gets whether a drop-down list should be disabled, or not.
This property mirrors the HTML disabled attribute.
The disabled property accepts and returns a boolean type value.
Value | Description |
---|---|
true | The drop-down list is disabled |
false | Default. The drop-down list is not disabled |
The disabled property returns true if the drop-down list is disabled, otherwise it returns false.