The disabled
property enables or disables an input button.
disabled |
Yes | Yes | Yes | Yes | Yes |
Return the disabled property.
var v = buttonObject.disabled
Set the disabled property.
buttonObject.disabled=true|false
Value | Description |
---|---|
true|false | Enable or disable a input button
|
A Boolean type value, true if the input button is disabled, otherwise it returns false.
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:
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: