Easy Tutorial
❮ Prop Screen Height Prop Element Scrolltop ❯

readOnly Attribute

Input Text Object

Example

Set the text field to read-only:

document.getElementById("myText").readOnly = true;

Definition and Usage

The readOnly attribute sets or returns whether the text field is read-only.

Read-only fields cannot be modified. However, users can still switch to the field using the tab key and select or copy its text.

Tip: To protect user interaction fields, use the disabled attribute instead.


Browser Support

All major browsers support the readOnly attribute.


Syntax

Return the readOnly attribute:

Set the readOnly attribute:

Attribute Values

Value Description
true false Specifies whether the text field is read-only<br>true - The text field is read-only<br>false - Default. The text field is modifiable

Technical Details

| Return Value: | Boolean, 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;

x output is:

true

Related Pages

HTML Reference: HTML <input> readonly Attribute


❮ Prop Screen Height Prop Element Scrolltop ❯