![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 a script when a user is pressing a key in HTML?
Use the onkeydown attribute. The onkeydown attribute triggers when the user is pressing a key.
Example
You can try to run the following code to execute a script on pressing a key −
<!DOCTYPE html> <html> <body> <p>Press a key inside the textbox.</p> <input type = "text" onkeydown = "display()"> <script> function display() { alert("You pressed a key!"); } </script> </body> </html>
Advertisements