Input Search value Attribute

Definition and Usage

value Sets or returns the value of the value attribute of the search field.

The HTML value attribute specifies the default value or the value entered by the user (or the value set by the script).

See also:

HTML Reference Manual:HTML <input> value Attribute

Example

Example 1

Change the text of the search field:

document.getElementById("mySearch").value = "跑车";

Try It Yourself

Example 2

Get the text of the search field:

var x = document.getElementById("mySeach").value;

Try It Yourself

Example 3

Example of the difference between the defaultValue and value attributes:

var x = document.getElementById("mySearch");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try It Yourself

Syntax

Return value attribute:

searchObject.value

Set value attribute:

searchObject.value = text

Attribute Value

Value Description
text Specifies the value of the search field.

Technical Details

Return Value: A string value representing the value of the search field.

Browser Support

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