Home > Article > Web Front-end > Execute script when user writes something in HTML search field?
Use the onsearch attribute in HTML to execute the script when the user types in the search box and presses the ENTER or x key.
You can try running the following code to implement the onsearch property −
<!DOCTYPE html> <html> <body> <p>Search something and press ENTER.</p> <input type = "search" id="inputID" onsearch = "display()"> <p><strong>Note:</strong> It won' work in Internet Explorer and Firefox.</p> <p id="test"></p> <script> function display() { var a = document.getElementById("inputID"); document.getElementById("test").innerHTML = "Searched for - " + a.value; } </script> </body> </html>
The above is the detailed content of Execute script when user writes something in HTML search field?. For more information, please follow other related articles on the PHP Chinese website!