Input Search readOnly attribute

Definition and Usage

readOnly Sets or returns 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:If you want to prevent users from interacting with the field, use disabled attribute.

See also:

HTML Reference Manual:Attribut readonly de <input> HTML

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 attribute:

searchObject.readOnly

Set the readOnly attribute:

searchObject.readOnly = true|false

attribute value

value description
true|false

Définit si le champ de recherche doit être en lecture seule

  • true - le champ de recherche est en lecture seule
  • false - par défaut. Le champ de recherche n'est pas en lecture seule

Détails techniques

Valeur de retour : Valeur booléenne, retourne si le champ de recherche est en lecture seule true; sinon retourne false.

Support du navigateur

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support