The disabled
property disables or enables a number field.
disabled |
Yes | 10.0 | Yes | Yes | Yes |
Return the disabled property.
var v = numberObject.disabled
Set the disabled property.
numberObject.disabled=true|false
Value | Description |
---|---|
true|false | Disable or enable a number field
|
A Boolean type value, true if the number field is disabled, otherwise false.
The following code shows how to check if a number field is disabled.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j av a 2s . c om-->
<input type="number" id="myNumber" value="2" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").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 number field.
<!DOCTYPE html>
<html>
<body>
<!-- w ww. ja v a 2 s.com-->
<input type="number" id="myNumber" value="2"><br><br>
<button onclick="disableBtn()">Disable Number Field</button>
<button onclick="enableBtn()">Enable Number Field</button>
<script>
function disableBtn() {
document.getElementById("myNumber").disabled = true;
}
function enableBtn() {
document.getElementById("myNumber").disabled = false;
}
</script>
</body>
</html>
The code above is rendered as follows: