• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

submit second form with first form submission

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()

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.

1 Solution
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)
	return true;

Open in new window

thenelsonAuthor Commented:
I decided to submit the first form in the php script that the second form posts to.
Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now