Solved

submit second form with first form submission

Posted on 2014-03-20
2
360 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
Comment Utility
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
Comment Utility
I decided to submit the first form in the php script that the second form posts to.
Thanks for your help.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

763 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

6 Experts available now in Live!

Get 1:1 Help Now