I'm binding on the keydown event with jQuery to allow some specific characters in a textbox. I'm trying to make my code cross browser and platform compliant. My main issue is that I can't find a way to map the received key-code to a valid char-code, especially for key code coming from the numeric pad (decimal separator, is it a comma or a period, etc.).
That is correct. There is no such mapping you can do; a keydown
may not even correspond to a character being inserted. Or Caps Lock might change the meaning of the keypress, and you can't sniff for that. And various other wrinkles.
If you want to know the character code your only option is to use the keypress
event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With