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
Solved

submit second form with first form submission

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

860 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