A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-onsearch-event-attribute/ below:

HTML onsearch Event Attribute - GeeksforGeeks

HTML onsearch Event Attribute

Last Updated : 11 Jul, 2025

This onsearch attribute works when a user presses the ENTER button or clicks on the x button. This event works with <input> element.

Supported Tags: 

Syntax: 

<element onsearch="script">

Attribute: This event contains single attribute script which contains the script to be run when event call.

Example: 

html
<!DOCTYPE html>
<html>

<head>
    <title>onsearch event</title>
    <style>
        .gfg {
            font-size:40px;
            color:green;
            font-weight:bold;
        }
        body {
            text-align:center;
        }
    </style>
</head>

<body>

    <div class="gfg">
      GeeksforGeeks
      </div>
    <h2>onsearch event attribute</h2>
    <input type="search" 
           id="geeks" 
           onsearch="geeksforgeeks()">
    
    <p id="geek"></p>

    <script>
        function geeksforgeeks() {
            let x = document.getElementById("geeks");
            document.getElementById("geek").innerHTML =
                   "Searching Content: " + x.value;
        }
    </script>
</body>

</html>

Output: 


Supported Browsers: The browsers supported by onsearch Event Attribute are listed below: 
 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4