Lee Quarella Lee Quarella - 1 year ago 131
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download