Javascript Reference - HTML DOM Input Button disabled Property








The disabled property enables or disables an input button.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = buttonObject.disabled 

Set the disabled property.

buttonObject.disabled=true|false

Property Values

Value Description
true|false Enable or disable a input button
  • true - The input button is disabled
  • false - Default. The input button is not disabled




Return Value

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

Example

The following code shows how to get if a button is disabled or not.


<!DOCTYPE html>
<html>
<body>
<input type="button" id="myBtn" value="My Button" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww  w.j a  v a2  s . com-->
    var x = document.getElementById("myBtn").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 enable a button.


<!DOCTYPE html>
<html>
<body>
<input type="button" id="myBtn" value="My Button">
<button onclick="disableBtn()">Disable </button>
<button onclick="enableBtn()">Enable</button>
<script>
function disableBtn() {<!--   www .  ja  va 2  s. co m-->
    document.getElementById("myBtn").disabled = true;
}
function enableBtn() {
    document.getElementById("myBtn").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: