codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Submit multiple forms with one button  baylock at 11:35 on Thursday, February 05, 2009
 

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


  Re: Submit multiple forms with one button  jack skellington at 14:18 on Saturday, March 06, 2010
 

Ground shaking content i get form your blog. Very nice post about multi form. Thanks for your beneficial information about itil v3 dumps[/url, [url=http://www.sure-braindumps.com/cert/SCJP.htm]java certification dumps and mcse braindumps certifications. These are the best certifications in the world.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: How to highlight text WITHIN a JTable cell?
•  Re: Problem to declare global variable in Object oriented perl
•  Re: dereferenceing a string to a constant name
•  Re: Submit multiple forms with one button
•  Re: Passing Password using $ssh->cmd
•  Re: ADODB.Recordset error (0x800A0CB3)
•  Re: Open a Modal Pop Up From a LinkButton In a GridView
•  Re: Need Javascript Multiple sidebar menu with sliding effects
•  Re: ASP.NET /Excel opening in frame Issue


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010