Prev Demo
Getting Keycode And Charcode In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script> // get key code function getKey(event) { event = event || window.event; var keyCode = event.which || event.keyCode; alert(keyCode); } // get char code function getChar(event) { event = event || window.event; var keyCode = event.which || event.keyCode; var typedChar = String.fromCharCode(keyCode); alert(typedChar); } </script> </head> <body> <h1>Getting keyCode and charCode in JavaScript</h1> <hr /> <h2>Get keycode</h2> Type here <input type="text" name="txt" id="txt" onkeypress="getKey(event)" /> <h2>Get charCode</h2> Type here <input type="text" name="txt" id="txt" onkeypress="getChar(event)" /> </body> </html>
Note: We DO NOT save your trial code in our database.
Output