views:

19

answers:

1

Hi,

In my project there is a button search which seems to be the default button to trigger when enter key has been pressed.

How can i detect a keydown event with jquery for a login button?

Its an asp.net project.

+2  A: 

Bind the "keypress" event handler to an element using jQuery.

See .keyPress() in the jQuery API.

Example code:

$('#login_button_id').keypress(function(event) {
  //prevent submission when enter key pressed
  if (event.keyCode == '13') {
    event.preventDefault();
  }
}
calvinf