JavaScript event keycode 13 | which key example code

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

Read: JavaScript keycode list

Get event keycode 13 in JavaScript

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

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


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



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

Leave a Reply

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