
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Execute Script on User Input in HTML Search Field
Use the onsearch attribute in HTML to execute a script when the user writes in a search field and press ENTER or x.
Example
You can try to run the following code to implement the onsearch attribute −
<!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>
Advertisements