javascript - Get Correct keyCode for keypad(numpad) keys -
i'm getting keycodes 96 105 when pressing keys on keypad [0..9] these keycodes correspond characters: 'a b c d e f g h i' instead of '0 1 2 3 4 5 6 7 8 9' when calling string.fromcharcode(event.keycode).
question:
have 3 input[type='text'] when user press keys on first input
if(this key numeric) write second input else if (this key alpha) write third input but gives 'a' when push 1 numpad. how can solve it?
use keypress handler:
[somelement].onkeypress = function(e){ e = e || event; console.log(string.fromcharcode(e.keycode)); } see also: this w3c testdocument
if want use keyup or keydown handler, can subtract 48 e.keycode number (so string.fromcharcode(e.keycode-48))
Comments
Post a Comment