HTML onsearch Event Attribute

Description

The event attribute onsearch allows you to specify whether the script fires when the user presses the Enter key or the x button in the <input> element ( type="search" ).

Syntax

<element onsearch="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onsearch event</title> 
    </head> 
    <body> 
    <p>Type something and hit enter:</p> 
    <input type="search" id="testInput" onsearch="testFunction()"> 
    <p id="info"> </p> 
<script> 
function testFunction() { 
  var z = document.getElementById("testInput").value; 
  document.getElementById("info").innerHTML = "You are looking for: " + z; 
} 
</script> 
  </body> 
</html>

Supported Tags

<input>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
??????