...

View Full Version : Submit two forms with one button



rushhh
07-25-2009, 05:36 PM
Hope this the right place to post this question.

I'm trying to Submit two forms with one button and one by one. Submit one by one is working. But can't finger out how to submit both at the same time.



<script type="text/javascript">
function f1Submit() {
var n1 = document.f1.t1.value;
var n2 = document.f2.t2.value;
if (!n1) {
document.f2.t2.value = n2;
document.f2.action="/test2.php"
document.f2.submit();
}
else if (!n2) {
document.f1.t1.value = n1;
document.f1.action="/test2.php"
document.f1.submit();
}
else if (n1 && n2){ //Submitting at the same time.
alert ("hello");
document.f1.t1.value = n1;
document.f2.t2.value = n2;
document.f1.action="/test2.php"
document.f2.action="/test2.php"
document.f1.submit();
document.f2.submit();

}
}
function submitAll() {
f1Submit();
}
</script>
</HEAD>

<BODY onload="document.f1.t1.focus();">
<form name="f1" method="get" enctype="multipart/form-data">

F1 NAME: <input type="text" name="t1" size="24" />
</form>

<form name="f2" method="get" enctype="multipart/form-data">

F2 NAME: <input type="text" name="t2" size="24" />
</form>

<form name="allSubmit">
<input type="button" name="btn1" value="Submit" onClick="submitAll()" />
</form>


Thanks

Philip M
07-25-2009, 06:50 PM
This is not straightforward. 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.


Quizmaster: What colour is created by mixing red and yellow?
Contestant: Green.
Quizmaster: No, red and yellow.
Contestant: Blue.

rushhh
07-25-2009, 09:32 PM
Is there a way I use AJAX to submit two forms at once?

Philip M
07-26-2009, 09:47 AM
Yes. See:-

http://9lessons.blogspot.com/2009/06/submit-multiple-forms-jquery-ajax.html

jQuery makes AJAX calls very simple so you shouldn't have any problem. Here is information on it: API/1.3/Ajax - jQuery JavaScript Library



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum