Input Text readOnly Attribute
Definition and Usage
readOnly
The property sets or returns whether the text field is read-only.
You cannot modify the read-only field. However, users can select, highlight it, and copy text from it.
Tip:If you want to prevent users from interacting with the field, use disabled attribute.
See also:
HTML Reference Manual:HTML <input> readonly Attribute
Example
Example 1
Set the text field to read-only:
document.getElementById("myText").readOnly = true;
Example 2
Determine if the text field is read-only:
var x = document.getElementById("myText").readOnly;
Syntax
Return the readOnly property:
textObject.readOnly
Set the readOnly property:
textObject.readOnly = true|false
attribute value
value | description |
---|---|
true|false |
Specifies whether the text field should be read-only
|
Technical Details
Return Value: | Boolean value, returns if the text field is read-only true ; otherwise return false . |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |