Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
151
rated 0 times [  156] [ 5]  / answers: 1 / hits: 85605  / 12 Years ago, tue, october 2, 2012, 12:00:00

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.


More From » jquery

 Answers
7

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



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

[#82801] Sunday, September 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;