...

View Full Version : Multiple form submit using single button



mrbadboy
12-20-2007, 04:48 PM
Hi,

I need to submit multiple forms with using single button. I've mentioned my code below.

<?
if(isset($_POST)){
print_r($_POST);
}
?>
<script type="text/javascript">
function form2Submit() {
document.f2.action="formsubmit2.php"
document.f2.submit();
alert('Form2 Submitted');
}

function form1Submit() {
document.f1.action="formsubmit2.php"
document.f1.submit();
document.getElementById("t1").value = '';
alert('Form1 Submitted');
}


function submitAllForm() {
form1Submit();
form2Submit();
}
</script>
</HEAD>

<body>
<form name="f1" method="post">
F1 NAME: <input type="text" name="t1" id="t1" size="24" value="txt1" />
</form>
<form name="f2" method="post">
F2 NAME: <input type="text" name="t2" id="t2" size="24" value="txt2" />
</form>
<input type="button" value="Submit" onClick="submitAllForm()" />
</body>

Its working properly in IE but not in Mozilla. do you have any idea ?

Thanks.

Fumigator
12-20-2007, 06:34 PM
Is there a compelling reason you are using two forms? Why not just use one form?

mrbadboy
12-20-2007, 08:24 PM
Hi buddy,

Thanx for your reply. Im using two forms with separate tabs. I need to fill two tabs. so with one buttion i've to submit two forms thats why.

Fumigator
12-20-2007, 08:35 PM
And why can't the two tabs go under the umbrella of a single form? I'm just trying to make your life simple. Usually the only reason for more than one form is because you actually need them to submit separately, so when you use two forms that you need to submit together, it defeats the point of having two forms and just complicates matters.

aWishResigned
12-20-2007, 08:38 PM
By 'having them in two tabs' do you mean that, depending on the answer to a particular question, the user either fills out one form or the other? If so, you can use one form and have two submit buttons (one in each tab) with the same name but different values. That way when the page loads, you can just parse the submit variable in PHP, performing one task for value A and another task for value B.

Hope this helps.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum