HTML onsearch Attribute
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">
Applies to:
The onsearch attribute can be used on the following element:
| Element | Attribute |
|---|---|
| <input type="search"> | onsearch |
Advertisement
Attribute Values
| Value | Description |
|---|---|
| script | Specifies the script to be run on onsearch |