Solved

Please fix this stupid jquery form submit

Posted on 2012-03-14
4
396 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
css, html 5 18
SharePoint 2013 List with Ratings 6 39
Polygon I google maps 1 16
How can I convert HTML files to .pdf files? 9 32
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now