Execute a script when a user is pressing a key in HTML?

HTMLWeb DevelopmentFront End Technology

Use the onkeydown attribute. The onkeydown attribute triggers when the user is pressing a key.


You can try to run the following code to execute a script on pressing a key −

<!DOCTYPE html>
      <p>Press a key inside the textbox.</p>
      <input type = "text" onkeydown = "display()">
         function display() {
            alert("You pressed a key!");
Published on 13-Mar-2018 12:31:08