Solved

Please fix this stupid jquery form submit

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

757 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

22 Experts available now in Live!

Get 1:1 Help Now