Yustme
Yustme

Reputation: 6255

Detecting keydown event with jQuery in ASP.NET

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

How can I detect a keydown event with jQuery for a login button?

It's an ASP.NET project.

Upvotes: 0

Views: 1050

Answers (1)

calvinf
calvinf

Reputation: 3914

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();
  }
}

Upvotes: 2

Related Questions