jQuery : get keycode and ascii

October 17th, 2012 § 0 comments

Keycode

You can get the keycode only in keyup or keydown event. if you are using jQuery event.which will hold the keycode

Charcode / Ascii

Charcode/Ascii is available only in keypress event. If you are in keypress event jQuery event.which will hold the ascii value instead of keycode.

You can easily convert the ascii to character with String.fromCharCode method.

Here is the working jsFiddle

Revath S Kumar [RSK]

- Rubyist / JavaScripter - Yeoman Team member - Open source enthusiast - Blogger @ PHPRepo and http://blog.revathskumar.com - Coder @ Whatznear - Google fanboy - jQuery lover

More Posts - Website - Twitter - Facebook - LinkedIn - Pinterest - Google Plus - YouTube