JavaScript keyup keycode on releasing the key | Example code

keyup and keydown give you information about the physical key that was pressed.

JavaScript keyup keycode Example

HTML example code. Using onkeyup property to call function.

<!DOCTYPE html>
<html>
<head>
  <script>

    function myFunction(event) {
      alert ("You pressed!");
      
    }
  </script>
</head>
<body>

  <input type="text" onkeyup="myFunction(event)">

</body>
</html>

Output:

JavaScript keyup keycode on releasing the key

addEventListener keyup example

<!DOCTYPE html>
<html>
<body>

  <script>
    document.addEventListener("keyup", function(e) {
      alert(e.code);
    });
  </script>

</body>
</html>

Do comment if you have any doubts and suggestion on this JS keycode tutorial.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.