Solved

Please fix this stupid jquery form submit

Posted on 2012-03-14
4
407 Views
Last Modified: 2012-03-14
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.

TIA

$(document).ready(function(){
	$('input').keydown(function(event){
		if(event.which==13){
			$(this).closest("form").submit();
		}
	});
})

Open in new window

0
Comment
Question by:Imaginx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Paul-B
ID: 37722954
This is what I use...

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

            event.preventDefault(); //avoids default action
            $(this).parent().find('input[type=submit]').trigger('click');       
 }

Open in new window

0
 
LVL 1

Author Comment

by:Imaginx
ID: 37722960
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.
0
 
LVL 4

Accepted Solution

by:
Paul-B earned 500 total points
ID: 37723067
hmm, possibly this then.

   $(this).parents('form').submit();

Open in new window


If this doesn't work I'm not sure without seeing more of the big picture.
0
 
LVL 1

Author Closing Comment

by:Imaginx
ID: 37723593
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.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question