Click to See Complete Forum and Search --> : How do I submit multiple forms with one button?


talon39
11-12-2003, 12:57 PM
Here's my situation. I need to make a form where each field gets emailed to a different set of recipients. My solution is to make each set of fields a seperate form with a seperate recipient tag, but have one submit button to submit all the forms. THis would create the illusion to the user that they are submitting one form, however all the right people get the correct fields emailed to them.

I tried the following:
<form name="Testform" action="http://website.com/cgi-sys/Form.cgi">
<input type=hidden name="recipient" value="email1@website.com">
<input type="text" name="textfield">
</form>

<form name="Secondform" action="http://website.com/cgi-sys/Form.cgi" onsubmit="document.Testform.submit(); return true;">
<input type=hidden name="recipient" value="email2@website.com">
<input type="text" name="textfield2">
<input type="submit">
</form>
However that only submits one form. Appearantly you can only submit one at a time in a single page unless there is some sort of action in between each. I thought maybe a single popup that updates after each form submits. However I wouldn't know how to code that. Does anyone know of a way to do what I'm trying to accomplish that works? Please post an example as my Javascript skills are pretty weak.

requestcode
11-12-2003, 02:19 PM
You could change your submit button to a normal button like this:
<input type="button" value="submit" onClick="doSubmit()">

Then in the head section of your document you would do this:
function doSubmit()
{
document.Testform.submit()
document.Secondform.submit()
}

talon39
11-12-2003, 05:01 PM
Holy Crap! That works. I have scored the Web for the last three weeks trying to find a solution to this and tried a half dozen suggestions and that is the first one that actually works. Thank You :D
Huge round of applause!

Why exactly does that method work where the others fail?