Reputation: 93
$("#username,#password").keypress(function(e)
{
//alert('');
if(e.keyCode == 13)
{
signIn();
}
});
The keypress event not calling if the enter button is pressed.
Upvotes: 1
Views: 3351
Reputation: 2631
Use keypress and which statement:
$("#username,#password").keypress(function(e) {
if (e.which == 13) {
//call here your function
}
});
Upvotes: 0
Reputation: 148110
Try using keyUp event.
$("#username,#password").keyup(function(e){
//alert('');
if(e.keyCode == 13)
{
signIn();
}
});
This is also working with keypress
$("#txt1").keypress(function(e) {
if (e.keyCode == 13) {
//signIn();
alert("keypress");
}
});
Upvotes: 4
Reputation: 4534
Key down is more appropriate:
$("#username,#password").keydown(function(e){
if(e.keyCode == 13)
{
signIn();
}
});
Upvotes: 2
Reputation: 5243
Are you sure it's not the signIn ();
function that's faulty? Because this seems to work just fine; http://jsfiddle.net/vDkBs/1/
Upvotes: 0
Reputation: 36214
e.which
instead of e.keyCode
because this is what jQuery guarantees to be on evente.preventDefault()
, because without it (if they are in a form) the form submitssubmit
eventUpvotes: 0