I Want get key value on keyPress with jQuery In textbox
Asked
Active
Viewed 4,502 times
0
-
7*None* of your other five questions received an acceptable answer? None? Mind you, if they all have this level of detail, people may not have tried very hard. The more effort you put into your questions, the better both the quality and quantity of the answers you'll receive. – T.J. Crowder Sep 14 '10 at 11:46
-
4I want people that write complete sentences and use question marks in questions. – halfdan Sep 14 '10 at 11:47
-
Consider looking at http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed – Shamim Hafiz - MSFT Sep 14 '10 at 11:49
2 Answers
2
Use the keypress
event as described here; there's an example on that page showing how to get the key code:
$('#target').keypress(function(event) {
if (event.keyCode == '13') {
event.preventDefault();
}
xTriggered++;
var msg = 'Handler for .keypress() called ' + xTriggered + ' time(s).';
$.print(msg, 'html');
$.print(event);
});
You want the event.keyCode
part.
This page may also be useful, it describes some "gotchas" around cross-browser keypress handling. jQuery may smooth some of those out for you, but good to be aware of them.

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875
1
$('#textbox').keypress(function(e) {
var code = e.keyCode || e.which;
});

fearofawhackplanet
- 52,166
- 53
- 160
- 253