Input Text readOnly property
Example
Set the text field to read-only:
document.getElementById("myText").readOnly = true;
Try it »
Definition and Usage
The readOnly property sets or returns whether the text field is read-only.
A read-only field cannot be modified. However, the user can still use the tab key to switch to the field, and can select or copy its text.
**Note:** To protect the user's interactive field, use disabled the attribute instead.
Browser support

All major browsers support the readOnly attribute.
Syntax
Return the readOnly attribute:
textObject
.readOnly
Set the readOnly attribute:
textObject
.readOnly=true|false
Attribute values
| Value | Description |
|---|---|
| true|false | Specifies whether the text field is read-only
|
Technical details
| Return Value: | Boolean, returns true if the text field is read-only, otherwise returns false |
|---|
More examples
Example
Check whether the text field is read-only:
var x = document.getElementById("myText").readOnly;
x The output is:
true
Try it »
Related pages
HTML Reference Manual: HTML readonly attribute
The Input Text object