Link to home
Create AccountLog in
Avatar of Glen Gibb
Glen GibbFlag 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?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Glen Gibb

ASKER

Tnx for the speedy reply!