When key is pressed can jQuery tell which one?
The backspace, delete, home or the arrow keys could they have a code when they are pressed?
$("#<%= TextBox1.ClientID %>").keypress(function () {
if (character#="1111"){
//code
}
});
jQuery simply wraps the event object which by default contains a property called which, this property contains the key code value based on the user input. See the below for how you can access the event object:
Your code with the event object
$("#<%= TextBox1.ClientID %>").keypress(function (e) {
alert(e.which); // The key that was pressed
});
You can find a list of every key code at the following url http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes.
Depending on what version of jQuery you’re using its recommended that you use the on method which handles delegation for the entire jQuery event wrapper.
$('#<%= TextBox1.ClientID %>').on('keypress', function(e) {
alert(e.which);
});