HTML event attribute onsearch








The onsearch attribute event is triggered when a user does the search by pressing the ENTER key in an <input> element with type="search".

We can also trigger the event by clicking 'X' inside the field.

What's new in HTML5

None.

Syntax

<elementName onsearch="script">

Supported Tags

<input type="search">




Browser compatibility

onsearch Yes No No Yes Yes

Example

<!DOCTYPE html>
<html>
<body>
<!--from w w  w  .j a  v a  2 s. c o  m-->
<input type="search" id="myInput" onsearch="myFunction()">

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

</body>
</html>

Click to view the demo