Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Text readOnly property

Input Text readOnly property

Input Text Object Reference The Input Text object

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

Internet Explorer Firefox Opera Google Chrome Safari

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
  • true - the text field is read-only
  • false - default. the text field can be modified
  • |

    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


    Input Text Object Reference The Input Text object