Skip to content

JavaScript keyup keycode on releasing the key | Example code

  • by

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 or suggestions 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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading