HTML onsearch Attribute

❮ HTML Attributes

Example

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

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

<script>
function myFunction() {
	var x = document.getElementById("myInput").value;
	document.getElementById("demo").innerHTML =  x;
}
</script>

Meaning

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




Standard Syntax

<element onsearch="script">



Browser Support




Status




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