Input Search defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Search


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

The default value is the value specified in the HTML value attribute.

You can use the defaultValue property to find out whether the contents of a search field have been changed.

Set the defaultValue property with the following Values

Value Description
value Sets the default value of the search field

Return Value

A String, representing the default value of the search field

The following code shows how to change the default value of a search field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
Search: <input type="search" id="mySearch" value="Food">

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/*from  w ww .j  a  v a  2  s. c o  m*/
    var x = document.getElementById("mySearch");
    var defaultVal = x.defaultValue;
    document.getElementById("demo").innerHTML = defaultVal;


Related Tutorials