Javascript Reference - HTML DOM Select disabled Property








The disabled property disables or enables a drop-down list.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = selectObject.disabled 

Set the disabled property.

selectObject.disabled=true|false 

Property Values

Value Description
true|false Disable or enable a drop-down list
  • true - The drop-down list is disabled
  • false - Default. The drop-down list is not disabled




Return Value

A Boolean type value, true if the drop-down list is disabled, otherwise false.

Example

The following code shows how to check if a drop-down list is disabled.


<!DOCTYPE html>
<html>
<body>
<select id="mySelect" disabled>
  <option>A</option>
  <option>B</option>
  <option>C</option>  
</select><!--  w  ww  .j  a  v  a 2s. c  o m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("mySelect").disabled;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to disable a drop-down list.


<!DOCTYPE html>
<html>
<body>
<!--from w w  w  . j  av a  2  s. co  m-->
<form>
<select id="mySelect">
  <option>A</option>
  <option>B</option>
</select>
</form>
<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    document.getElementById("mySelect").disabled = true;
}
</script>

</body>
</html>

The code above is rendered as follows: