HTML DOM Input Search value property

The HTML DOM Input search value property is associated with the input element having type=”search” and the value attribute. It is used to return the value of input search field value attribute or to set it. This property is used for specifying a default value for search field and it also changes the value to user input.


Following is the syntax for −

Setting the value property −

searchObject.value = text;

Here, text is used for specifying the value for the search field.


Let us look at an example for the input search value property −

Live Demo

<!DOCTYPE html>
<h1>Input search Value property</h1>
FRUITS: <input type="search" id="SEARCH1" name="fruits">
<p>Get the above element value by clicking the below button</p>
<button onclick="getValue()">Get Value</button>
<p id="Sample"></p>
   function getValue() {
      var t = document.getElementById("SEARCH1").value;
      document.getElementById("Sample").innerHTML = "The value for the input field is : "+t;


This will produce the following output −

On typing some text and then clicking on the “Get Value” button −

Updated on: 19-Feb-2021


Kickstart Your Career

Get certified by completing the course

Get Started