Reputation: 1918
I Want get key value on keyPress with jQuery In textbox
Upvotes: 0
Views: 4507
Reputation: 53378
$('#textbox').keypress(function(e) {
var code = e.keyCode || e.which;
});
Upvotes: 1
Reputation: 1074198
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.
Upvotes: 2