Avatar of Glen Gibb
Glen Gibb
Flag for Canada asked on

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?
jQuery

Avatar of undefined
Last Comment
Glen Gibb

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Glen Gibb

ASKER
Tnx for the speedy reply!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy