What is the usage of onsearch event in JavaScript?

HTMLJavascriptProgramming Scripts

The onsearch event is useful for search i.e. a user press ENTER or “x” key in input element. The type for <input> is search, since it is for users to search. The onsearch event isn’t supported in Internet Explorer, Firefox, and Opera.


You can try to run the following code to learn how to implement onsearch event in JavaScript.

<!DOCTYPE html>
      <p>Write what you want to search below and press "ENTER".</p>

      <input type = "search" id = "newInput" onsearch = "searchFunc()">
         function searchFunc() {
            var a = document.getElementById("newInput");
            document.write("Searched = " + a.value);
Updated on 22-May-2020 11:28:01