Can someone help me, how can i define the keyCode,which,charcode into variable. below is my code. but seems not working in Firefox. i already try at Google chrome and i.e. and its work fine.
$(function() {
$('#txtInput').keydown(function(event) {
var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
//number
if (Key >= 48 && Key <= 57)
return true;
//numpad
else if (Key >= 96 && Key <= 105)
return true;
//backspace,tab
else if (Key >= 8 && Key <= 9)
return true;
else return false;
});
});
I think
event.whichis enough to check thekeyCodeand work fine for all browsers.According to jQuery doc:
More
CODE
Working sample
Read more about event.which