The readOnly
property sets or gets whether a number field is read-only.
readOnly |
Yes | 10.0 | Yes | Yes | Yes |
Return the readOnly property.
var v = numberObject.readOnly
Set the readOnly property.
numberObject.readOnly=true|false
Value | Description |
---|---|
true|false | Set whether a number field should be read-only
|
A Boolean type value, true if the number field is read-only, otherwise false.
The following code shows how to check if a number field is read-only.
<!DOCTYPE html>
<html>
<body>
<!--from w w w. j a v a 2 s. c om-->
<input type="number" id="myNumber" value="2" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").readOnly;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a number field to read-only.
<!DOCTYPE html>
<html>
<body>
<input type="number" id="myNumber" value="2">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w ww. j a v a2 s . co m-->
<script>
function myFunction() {
document.getElementById("myNumber").readOnly = true;
}
</script>
</body>
</html>
The code above is rendered as follows: