Latest web development tutorials
 

onsearch Event

< Event Object

Example

Execute a JavaScript when submitting a search:

<input type="search" onsearch="myFunction()">
Try it Yourself »

Definition and Usage

The onsearch event occurs when a user presses the "ENTER" key or clicks the "x" button in an <input> element with type="search".


Browser Support

The numbers in the table specify the first browser version that fully supports the event.

Event
onsearch Yes Not supported Not supported Yes 15.0

Syntax

In HTML:

<element onsearch="myScript">
Try it Yourself »

In JavaScript:

object.onsearch=function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("search", myScript);
Try it Yourself »

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <input type="search">
DOM Version: Level 3 Events

< Event Object