Skip to content

JavaScript event keycode 13 | which key example code

key 13 keycode is for ENTER the key. Using onkeypress can get the key code and name.

Read: JavaScript keycode list

Get event keycode 13 in JavaScript

HTML example code, ENTER keypress event. If the user presses the enter key then an alert box will show.

<!DOCTYPE html>
<html>
<body>
  <input type="text" id="myInput">

  <script>

    document.onkeypress = function(event) {
      if (event.which == 13) {
        alert(event.code + " " + event.which); 
      }
    }
  </script>

</body>
</html>

Output:

JavaScript event keycode 13

Or use window object

window.onkeypress = function(event) {
      if (event.which == 13) {
        alert(event.code + " " + event.which); 
      }
    }

Do comment if you have any doubts and suggestions on this JS keycode example.

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

OS: Windows 10

Code: HTML 5 Version

1 thought on “JavaScript event keycode 13 | which key example code”

Leave a Reply

Discover more from Tutorial

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

Continue reading