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.

Example

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

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

      <input type = "search" id = "newInput" onsearch = "searchFunc()">
      <script>
         function searchFunc() {
            var a = document.getElementById("newInput");
            document.write("Searched = " + a.value);
         }
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 15:41:47
Advertisements