The disabled
property disables or enables a drop-down list.
disabled |
Yes | Yes | Yes | Yes | Yes |
Return the disabled property.
var v = selectObject.disabled
Set the disabled property.
selectObject.disabled=true|false
Value | Description |
---|---|
true|false | Disable or enable a drop-down list
|
A Boolean type value, true if the drop-down list is disabled, otherwise false.
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:
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: