Input Number disabled Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

The disabled property sets or gets whether a number field should be disabled.

This property reflects the HTML disabled attribute.

Set the disabled property with the following Values

Value Description
true|false Sets whether a number field should be disabled
  • true - The number field is disabled
  • false - Default. The number field is not disabled

Return Value

A Boolean, returns true if the number field is disabled, otherwise it returns false

The following code shows how to disable a number field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<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() {//w w  w  .  j a va2s  .  com
    document.getElementById("myNumber").disabled = true;
}
function enableBtn() {
    document.getElementById("myNumber").disabled = false;
}
</script>

</body>
</html>

Related Tutorials