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

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


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)

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?
Glen Gibb
Glen Gibb
1 Solution
with jQury you don't have to use : code = (e.keyCode) ? e.keyCode : e.which;

Check here :

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

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