adalby
12-17-2005, 12:25 PM
Is it possible with Javascript to submit 2 different forms at the same time with only 1 submit button? I've searched everywhere and most places say it's not possible.
Thanks,
Aaron
Thanks,
Aaron
|
Click to See Complete Forum and Search --> : Submit 2 Forms With 1 Button??? adalby 12-17-2005, 12:25 PM Is it possible with Javascript to submit 2 different forms at the same time with only 1 submit button? I've searched everywhere and most places say it's not possible. Thanks, Aaron jscott 12-17-2005, 01:18 PM You can get the forms with Javascript and fire them that way. I'm not saying you should do this but I don't know what you are really trying to accomplish. function submitForms() { var firstForm = document.forms[0]; var secondForm = document.forms[1]; firstForm.submit(); secondForm.submit(); } <img src="yourButton.gif" onclick="submitForms()"> felgall 12-17-2005, 02:05 PM That wont work because once the first form is submitted you are transferred to a different page. The only way you can get it to work is if you combine the forms into one form and then modify the server side processing to perform both processes. adalby 12-17-2005, 02:31 PM Thanks but your code did not work it only submitted the last form. I'm trying to just send 2 forms and there info at the same time. Right now I have 2 forms but it would be great if I only had 1 form and sent it to 2 different cgi scripts. Here is my example code with your javascript. <HTML> <HEAD> <TITLE></TITLE> <script type="text/javascript"> function submitForms() { var firstForm = document.forms[0]; var secondForm = document.forms[1]; firstForm.submit(); secondForm.submit(); } </script> </HEAD> <BODY> <FORM action=/cgi-bin/EZ/csvwrite.pl method=POST ENCTYPE="multipart/form-data" name=form1> <font face="Verdana" size="2"><b>Field 1:</b> <input type="text" name="field1" size="52" value="Type something, anything."><br> <b> Field 2:</b> <input type="checkbox" name="field2" value="Checked" tabindex="2" checked><br> <b>Field 3:</b> 1<input type="radio" name="field3" value="1"> 2<input type="radio" name="field3" value="2"> 3<input type="radio" name="field3" value="3"> 4<input type="radio" name="field3" value="4"> 5<input type="radio" name="field3" value="5" checked> 6<input type="radio" name="field3" value="6"> 7<input type="radio" name="field3" value="7"> 8<input type="radio" name="field3" value="8"> 9<input type="radio" name="field3" value="9"> 10<input type="radio" name="field3" value="10"><br> <b> Field 4: <input type="file" name="field4"></b><br> <br> <b>Field 6:</b> <input type="text" name="field6" size="52" value=""><br> <b>Email:</b> <input type="text" name="email" size="52" value=""><br> </FORM> <br> <hr> <br> <FORM action=/cgi-bin/EZ/csvwrite2.pl method=POST ENCTYPE="multipart/form-data" name=form2> <font face="Verdana" size="2"><b>Field 1:</b> <input type="text" name="field1" size="52" value="Type something, anything."><br> <b> Field 2:</b> <input type="checkbox" name="field2" value="Checked" tabindex="2" checked><br> <b>Field 3:</b> 1<input type="radio" name="field3" value="1"> 2<input type="radio" name="field3" value="2"> 3<input type="radio" name="field3" value="3"> 4<input type="radio" name="field3" value="4"> 5<input type="radio" name="field3" value="5" checked> 6<input type="radio" name="field3" value="6"> 7<input type="radio" name="field3" value="7"> 8<input type="radio" name="field3" value="8"> 9<input type="radio" name="field3" value="9"> 10<input type="radio" name="field3" value="10"><br> <b> Field 4: <input type="file" name="field4"></b><br> <br> <b>Field 6:</b> <input type="text" name="field6" size="52" value=""><br> <b>Email:</b> <input type="text" name="email" size="52" value=""><br> </FORM> <input type=button onclick="submitForms()" value="Submit"> </BODY> </HTML> adalby 12-18-2005, 01:19 PM Does anyone else have any ideas on this? Thanks! felgall 12-18-2005, 01:22 PM You can only submit one form at a time as a browser window can't display two things in the same spot at the same time. If you want two things to happen then have the script that processes the first part of the form call a second script to process the rest of the form. adalby 12-18-2005, 02:14 PM Thanks Stephen! I was affraid of that. How do you mean exactly having the second script process the rest of the form. My 2 scripts are both cgi scripts and are the same they just write to 2 different databases? Do you have any examples or a way to call the 2nd script once the first is processed? Thanks, Aaron webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |