views:

28

answers:

1

How to convert keycode to character using javascript

var key_code = 65;

result should be

character = "a";
+1  A: 

String.fromCharCode() is what you want:

The fromCharCode() method converts Unicode values to characters.

Syntax

String.fromCharCode(n1, n2, ..., nX)
Skilldrick
Notice that String.fromCharCode(65) == 'A', to get 'a' a call to .toLowerCase() is needed.
Arrix
Only if you've got the "key code" from a `keypress` event. In `keyup` and `keydown` events, the `keyCode` property has nothing to do with characters.
Tim Down