The disabled
property enables or disables a checkbox.
disabled |
Yes | Yes | Yes | Yes | Yes |
Return the disabled property.
var v = checkboxObject.disabled
Set the disabled property.
checkboxObject.disabled=true|false
Value | Description |
---|---|
true|false | Enable or disable a checkbox. Possible values:
|
A Boolean type value returns true if the checkbox is disabled, otherwise it returns false.
The following code shows how to check if a checkbox is disabled.
<!DOCTYPE html>
<html>
<body>
<!-- w ww . jav a 2 s. co m-->
Checkbox: <input type="checkbox" id="myCheck">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myCheck").disabled;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to disable and endisable a checkbox.
<!DOCTYPE html>
<html>
<body>
<!--from w w w.j a v a 2 s . c o m-->
Checkbox: <input type="checkbox" id="myCheck">
<button onclick="disable()">Disable checkbox</button>
<button onclick="enable()">Enable checkbox</button>
<script>
function disable() {
document.getElementById("myCheck").disabled = true;
}
function enable() {
document.getElementById("myCheck").disabled = false;
}
</script>
</body>
</html>
The code above is rendered as follows: