JavaScript onkeydown keycode | Get value of the pressed key example

You can call function from element using onkeydown property. When a key is pressed down get the pressed key, use the keyCode and which event properties.

Note: The onkeypress event is similar to the onkeydown event, but it does not fire for all key types in all browsers.

JavaScript onkeydown keycode example

This HTML example oce illustrates the use of the onkeydown event:

<!DOCTYPE html>
    function GetChar(event){
      var x = event.keyCode;
      alert ("The Unicode key code is: " + x);

  <input size="40" placeholder="Write.." onkeydown="GetChar(event);"/>



JavaScript onkeydown keycode

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

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.