bl0b bl0b - 7 months ago 21
Javascript Question

Get key value of a key pressed

I don't find how to get the value of a key pressed.
I currently have

$('#info_price').bind('keydown',function(evt){
alert(evt.keyCode);


but it return '49' when I press on 1 instead of returning '1'.

Edit: I'm aware that Ascii code of key '1'.

The final goal is to allow people to only write digit into the input. So i want to detect the non digit and not display them.

Answer

As it's told in comment it's ASCII code. To get it as character you can do:

alert(String.fromCharCode(evt.keyCode));