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 0-9 return keyCodes of 96-105 which, according to fromCharCode() are the lower case letters a-i. How do I get keydown events of the numberpad to resolve to the appropriate number?
You don’t: you use the
keypressevent. Thekeypressevent is the only event that will give you reliable information about typed characters. Your existing code will work if you simply changekeydowntokeypress.