Execute a JavaScript when submitting a search:
The onsearch event is not supported in Internet Explorer, Firefox.
<!DOCTYPE html> <html> <body> <p>Write something in the search field and press "ENTER".</p> <input type="search" id="myInput" onsearch="myFunction()"> <p id="demo"></p> <script> function myFunction() {/*w ww. j av a 2 s .com*/ var x = document.getElementById("myInput"); document.getElementById("demo").innerHTML = "You are searching for: " + x.value; } </script> </body> </html>
The onsearch event occurs when a user presses the "ENTER" key or clicks the "x" button in an <input> element with type="search".
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <input type="search"> |