• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

jquery - if ( keyCode == 13) allows all key values

Experts,

I'm trying to submit a form when the enter key is pressed.  This code executes when ANY key is pressed!

function onKeyUp(e) {
  if ( e.keyCode == 13)
     $(this).closest('form').submit();
}

I've also tried "code = (e.keyCode) ? e.keyCode : e.which;" to set the value.  The keyCode value is fine.

But e.keyCode == 77 slips right through the filter!

Any ideas?
0
Glen Gibb
Asked:
Glen Gibb
1 Solution
 
leakim971PluritechnicianCommented:
with jQury you don't have to use : code = (e.keyCode) ? e.keyCode : e.which;

Check here :
http://api.jquery.com/event.which/

The event.which property normalizes event.keyCode and event.charCode.
0
 
Glen GibbAuthor Commented:
Tnx for the speedy reply!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now