Solved

submit second form with first form submission

Posted on 2014-03-20
2
370 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
[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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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…
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…

717 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