Input Number readOnly Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

The readOnly property sets or gets whether a number field should be read-only.

This property reflects the HTML readonly attribute.

Set the readOnly property with the following Values

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

Return Value

A Boolean, returns true if the number field is read-only, otherwise it returns false

The following code shows how to Set a number field to read-only:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" value="2" readonly>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  w w w.j  a  va  2s.  c  o m*/
    var x = document.getElementById("myNumber").readOnly;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials