javascript - OnKeyDown and String.FromCharCode -


i've question concerning onkeydown event. onkeydown event gives keycode don't know kind of code given. basically, using string.fromcharcode method real character thought ascii-code. worked fine until tried numbers numpad. if type '2' using key above 'w' that's ok, '2' numpad keycode given 98 (which 'b' ascii code).

i looking @ page , there's same problem. example supposed prevent user typing numbers. works fine numbers on top of first character (for lack of better name), can type numbers using num pad.

do have idea problem is? (is ascii code ? using wrong event ? )...

thx...

to prevent numbers use onkeypress instead:

onkeypress="return preventdigits(event);" ... function preventdigits(evt) {     evt = evt || window.event;     var keycode = evt.keycode || evt.which;7     var num = parseint(string.fromcharcode(keycode), 10);     return isnan(num); } 

live example: http://jsfiddle.net/yahavbr/vwc7a/


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -