Latest web development tutorials

HTML DOM Input Text readOnly property

Input Text Object Reference Input Text Object

Examples

Set the text fields read-only:

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

try it"


Definition and Usage

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

Read-only field can not be modified. However, users can still use the tab key to switch to the field, you can also select or copy its text.

Tip: To protect the user's interaction domain, use the disabled property instead.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support readOnly property.


grammar

Back readOnly attributes:

textObject .readOnly

Set readOnly properties:

textObject .readOnly = true | false

Property Value

value description
true | false The provisions of the text field is read-only
  • true - read-only text field
  • false - default. Editable text fields

Technical details

return value: Boolean value that, if the read-only text field returns true, false otherwise


More examples

Examples

See text field is read-only:

var x = document.getElementById ( "myText") readOnly.;

x The output is:

true

try it"


Related Pages

HTML Reference Manual: HTML <the INPUT> Readonly property


Input Text Object Reference Input Text Object