HTML onsearch Attribute

❮ HTML Attributes


<label for="myInput">Search: </label><input type="search" id="myInput" onsearch="myFunction()">

<p>You are searching for: <output id="demo"></output></p>

function myFunction() {
	var x = document.getElementById("myInput").value;
	document.getElementById("demo").innerHTML =  x;


The onsearch attribute fires when the user writes something in a search input field.

Standard Syntax

<element onsearch="script">

Browser Support


Applies to:

The onsearch attribute can be used on the following element:

Element Attribute
<input type="search"> onsearch

Attribute Values

Value Description
script Specifies the script to be run on onsearch
❮ HTML Attributes