Javascript DOM HTML Input Number disabled Property set

Introduction

Disable a number field:

document.getElementById("myNumber").disabled = true;

Click the button to disable the number field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" value="2">
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/*from w w w.j  a  v a 2s . c o m*/
  document.getElementById("myNumber").disabled = true;
}
</script>

</body>
</html>

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

This property mirrors the HTML disabled attribute.

The disabled property accepts and returns a boolean type value.

Value Description
true The number field is disabled
falseDefault. The number field is not disabled

The disabled property returns true if the number field is disabled, otherwise it returns false.




PreviousNext

Related