Input Number readOnlyProperty
Examples
Set the number field to read-only:
document.getElementById("myNumber").readOnly = true;
Output result:
Try it yourself »
Definition and Usage
The readOnly property is used to set or return whether the number field is read-only.
Read-only fields cannot be modified. However, the content of the field can be copied.
This property reflects the HTML readonly attribute.
Tip:To ensure the accuracy of form data, you can usedisabledattribute instead.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the readOnly property.
Note:Internet Explorer 9 and earlier IE versions do not support <input> elements with the type="number" attribute.
Syntax
Return the readOnly property:
numberObject.readOnly
Set the readOnly property:
numberObject.readOnly=true|false
Property Values
| Value | Description |
|---|---|
| true|false | Describes whether the number field is read-only
|
Technical Details
| Return value: | A Boolean value, returning true if the number field is read-only, otherwise returning false. |
|---|
More Examples
Examples
Check whether the number field is read-only:
var x = document.getElementById("myNumber").readOnly;
xThe output result is:true
Try it yourself »
Related Pages
HTML Reference Manual:HTML <input> readonly attribute
Input Number Object Other Extensions