Home  >  Article  >  Web Front-end  >  What is the usage of onsearch event in JavaScript?

What is the usage of onsearch event in JavaScript?

WBOY
WBOYforward
2023-09-27 15:49:02844browse

What is the usage of onsearch event in JavaScript?

The onsearch event is useful for searches where the user presses the ENTER or "x" key within an input element. The type of is search because it is for users to search. Internet Explorer, Firefox, and Opera do not support the onsearch event.

Example

You can try running the following code to learn how to implement the 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>

The above is the detailed content of What is the usage of onsearch event in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete