Lee Quarella Lee Quarella - 4 months ago 55
Javascript Question

Javascript numberpad keycode parsing

I am attempting to parse keydown events from the numberpad with the following:

$('#myDiv').keydown(function(e) {
val = String.fromCharCode(e.which)

The problem is that keypad
return keyCodes of
which, according to
are the lower case letters
. How do I get keydown events of the numberpad to resolve to the appropriate number?


You don't: you use the keypress event. The keypress event is the only event that will give you reliable information about typed characters. Your existing code will work if you simply change keydown to keypress.