Javascript Reference - HTML DOM Input Checkbox disabled Property








The disabled property enables or disables a checkbox.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = checkboxObject.disabled 

Set the disabled property.

checkboxObject.disabled=true|false 

Property Values

Value Description
true|false Enable or disable a checkbox.
Possible values:
  • true - The checkbox is disabled
  • false - Default. The checkbox is not disabled




Return Value

A Boolean type value returns true if the checkbox is disabled, otherwise it returns false.

Example

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:





Example 2

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: