Please fix this stupid jquery form submit

The form doesn't submit.
The action does trigger when pressing enter on the keyboard.

I know which line of code needs to change, '$(this).closest("form").submit();'

Just unsure of what it needs to change to.

It needs to be dynamic, so that it works on any form.
So anytime someone clicks enter in an input field, it will submit that input's parent form.



Open in new window

Who is Participating?
hmm, possibly this then.


Open in new window

If this doesn't work I'm not sure without seeing more of the big picture.
This is what I use...

 if (event.keyCode == '13') { 

            event.preventDefault(); //avoids default action

Open in new window

ImaginxAuthor Commented:
I don't typically have submit inputs, i use query/javascript to submit the forms.
There are a TON of forms through out this site, so it isn't worth while to go back and change.

Unfortunately, I didn't write the site, just updating it ... Been an absolute nightmare.
ImaginxAuthor Commented:
I thought I had tried that,  realized I had tried $(this).parent('form').submit(); with .parents() as the singular form - probably why it didn't work.

Thanks for the help !! worked perfectly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.