Input Search readOnly Attribute

Definition and Usage

readOnly Attribute to set or return whether the search field should be read-only.

Read-only fields cannot be modified. However, users can select, highlight it, and copy text from it.

This property reflects the HTML readonly attribute.

Tip: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 search field to read-only:

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

Try it yourself

Example 2

Determine if the search field is read-only:

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

Try it yourself

Syntax

Return the readOnly property:

searchObject.readOnly

Set the readOnly property:

searchObject.readOnly = true|false

attribute value

value description
true|false

Specifies whether the search field should be read-only

  • true - The search field is read-only
  • false - Default. The search field is not read-only

Technical Details

Return value: Boolean value, returns if the search 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