Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Please fix this stupid jquery form submit

Posted on 2012-03-14
4
Medium Priority
?
411 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)
Suggested Courses

610 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