Input Text readOnlyProperty
Example
Set the text field to read-only:
document.getElementById("myText").readOnly = true;
Try it Yourself »
Definition and Usage
The readOnly property sets or returns whether a text field is read-only.
Read-only fields cannot be modified. However, users can still tab to the field, and can select or copy its text.
Tip:To protect user interaction fields, use thedisabledattribute instead.
Browser Support
![]()
All major browsers support the readOnly property.
Syntax
Return the readOnly property:
textObject.readOnly
Set the readOnly property:
textObject.readOnly=true|false
Property Values
| Value | Description |
|---|---|
| true|false | Specifies whether the text field is read-only
|
Technical Details
| Return value: | A Boolean value, returns true if the text field is read-only, otherwise returns false. |
|---|
More Examples
Example
Check if the text field is read-only:
var x = document.getElementById("myText").readOnly;
xThe result is:
true
Try it Yourself »
Related Pages
HTML Reference Manual:HTML <input> readonly attribute
Input Text Object Other Extensions