|
Hello there,
I'm new among you and I subscribed here because of a (quite old) thread here having the same title as mine.
In this one, a user found an elegant way to submit multiple forms (selected by ID) using a single button.
<SCRIPT LANGUAGE="JavaScript">
/* Collect all forms passed by array and post it */
function submitFormsById(arFormsSubmit)
{
var formCollector = document.createElement("form");
with(formCollector)
{
method = "post";
action = "http://www.mysite.com/data_process.php";
name = "formCollector";
id = "formCollector";
style.display = "none";
}
for(var ix = 0; ix<arFormsSubmit.length;ix++)
appendFormVals2Form(document.getElementById(arFormsSubmit[ix]), formCollector);
document.body.appendChild(formCollector);
formCollector.submit();
}
/* Function: add all elements from ``frmCollectFrom´´ and append them to ``frmCollector´´ before returning ``frmCollector´´*/
function appendFormVals2Form(frmCollectFrom, frmCollector)
{
var frm = frmCollectFrom.elements;
for(var ix = 0 ; ix < frm.length ; ix++)
frmCollector.appendChild(frm[ix]);
return frmCollector;
}
</SCRIPT>
This ends with the button of course:
<INPUT TYPE="submit" value="submit" name="xxxxx" onClick="submitFormsById(Array('form1','form2','form3', etc..))">
This is almost perfect as it sends the data from all the forms alright but the data retrieved is incomplete...
This is what I get with two forms retrieved at once:
section1=14
title1=
reference1=
company1=2
weight1=
newprice1=120.00
oldprice1=130.00
x1=7
y1=
z1=64
hex1=
ups1=
section2=11
title2=
reference2=
company2=4
weight2=
newprice2=150.00
price2=200.00
x2=2
y2=
z2=64
hex2=
ups2=
Does someone understand what is going on?
I know it's not a mistake I made because if you switch the places of, for instance, "weight" and "company" in the initial form, you'll end up with a value retrieved for "weight" and none for "company".
Something to do with the "ix" loop inside the script I guess...
In the thread where I found this code, the final user had the same problem as mine but the one who created the code never corrected it, unfortunately.
Any help?
Thank you
|
|
|
|
|
|
|
|
|
|