Solved

submit second form with first form submission

Posted on 2014-03-20
2
364 Views
Last Modified: 2014-03-20
I want to submit a second form with a first form submission. The first form has:
    <form onsubmit="return updateAmount();" ...

The javascript function updateAmount has:
      function updateAmount()
      {
            document.getElementById("theform").submit();
      }

And the second form has
   <form id="theform" ...

But the second form ("theform") is not submitting with the first form submission.

What am I doing wrong?

BTW: There are times I submit the second form ("theform")  without submitting the first form so I can't just combine them.

TIA
0
Comment
Question by:thenelson
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39943092
You should submit the first one using ajax :

function updateAmount() {
	var form = document.getElementById("theform");

	// https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started#Step_3_.E2.80.93_A_Simple_Example
	if(window.XMLHttpRequest) { // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}
	if (!httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	if(form.method.toLowercase()=="get") {
		httpRequest.open('GET', url, false);
	}
	else {
		httpRequest.open('POST', url, false);
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}

	// https://code.google.com/p/form-serialize/
	var serializedForm = serialize(form)
	httpRequest.send(serializedForm);
	return true;
}

Open in new window

0
 
LVL 39

Author Closing Comment

by:thenelson
ID: 39944417
I decided to submit the first form in the php script that the second form posts to.
Thanks for your help.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
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)

773 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