Javascript Reference - HTML DOM Input Number disabled Property








The disabled property disables or enables a number field.

Browser Support

disabled Yes 10.0 Yes Yes Yes

Syntax

Return the disabled property.

var v = numberObject.disabled 

Set the disabled property.

numberObject.disabled=true|false

Property Values

Value Description
true|false Disable or enable a number field
  • true - The number field is disabled
  • false - Default. The number field is not disabled




Return Value

A Boolean type value, true if the number field is disabled, otherwise false.

Example

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:





Example 2

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: