Input Search defaultValue Attribute

Definition and usage

defaultValue The property sets or returns the default value of the search field.

Note:The default value is HTML value attribute value specified in

The difference between defaultValue and value properties is that defaultValue contains the default value, while value contains the current value after some changes. If no changes have been made, defaultValue and value are the same (see the example below).

The defaultValue property is very useful when you want to check if the content of the search field has changed.

Instance

Example 1

Change the default value of the search field:

document.getElementById("mySearch").defaultValue = "Drinks";

Try it yourself

Example 2

Get the default value of the search field:

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

Try it yourself

Example 3

Example to show the difference between defaultValue and value properties:

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

Try it yourself

Syntax

Return the defaultValue property:

searchObject.defaultValue

Set defaultValue Property:

searchObject.defaultValue = value

Attribute Value

Value Description
value Specifies the default value of the search field.

Technical Details

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

Browser Support

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