You are here: Reference > JavaScript > client-side > event handling > events > onsearch

onsearch event | search event

Browser support:
Occurs when the user presses the ENTER key or clicks the 'Erase search text' button (x) in an input:search field.
If the INCREMENTAL attribute of a input:search element is set to 'true', then changing the contents of the input:search field also causes the onsearch event to be fired.

How to register:

<ELEMENT onsearch="handler">

In JavaScript:
object.onsearch = handler;
object.addEventListener ("search", handler, useCapture);
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers. The properties of the event object contain additional information about the current event. To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript.

Basic information:

Bubbles No
Cancelable No
Event object Event

Actions that invoke the onsearch event:

  • Pressing the ENTER key or clicking the 'Erase search text' button in a search control.

Example HTML code 1:

This example illustrates the use of the onsearch event:
    <script type="text/javascript">
        function OnSearch (input) {
            alert ("The current value of the search field is\n" + input.value);
    Please specify the text you want to find and press ENTER!
    <input type="search" name="search" autosave="" results="10" onsearch="OnSearch (this)"/>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content