[Javascript] submitting java script array using Form

TomMallard mallard at serv.net
Tue Mar 11 14:34:13 CST 2003


This idea may work...collection to collection, didn't test it...

document.form2.list[] = document.form1.list[];

tom mallard
seattle

-----Original Message-----
From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
Behalf Of Reuben D. Budiardja
Sent: Tuesday, March 11, 2003 10:49 AM
To: javascript at LaTech.edu
Subject: [Javascript] submitting java script array using Form



Hello,
I am wondering if there's an easy way to do this. Let me describe the
problem.

I have 2 forms, in form 1, I have a set of checkboxes with the same name but
each with different value. The checkboxes were generated using PHP on server
side. I want it when the user check the checkbox, it value goes to an array,
or something.

Then the submit button is on Form2. Form2 only contains the submit button
and
nothing else visible (it can have INPUT TYPE=HIDDEN of course).

When user click the submit button, I want all the values that are checked on
the checkbox to be submitted.

So the very short version of the problem, how do I transfer those values
from
Form1 to Form2 ? Via javascript variable?
Here what I am thinking:

<FORM NAME="build">
  <INPUT TYPE="CHEKBOX" NAME="list[]" VALUE="value 1">
  <INPUT TYPE="CHEKBOX" NAME="list[]" VALUE="value 1">
  <INPUT TYPE="CHEKBOX" NAME="list[]" VALUE="value 1">
</FORM>

<FORM NAME="send">
  <INPUT TYPE=HIDDEN NAME="list[]">
  <INPUT TYPE="BUTTON" onClick="sendList();">
</FORM>

<SCRIPT>
// Pseudocode -- does not work
function sendList()
  {
  // Try to access the value checkbox in form 1 and assign it to form 2
  var checbox_val = document.getElementsByName["build"].list;
  document.getElementsByName["send"].list = checkbox_val;
  document.getElementsByName["send"].submit();
  }
</SCRIPT>

I am trying to do it using the DOM way (I am not going to worry about older
browser, primary target audience use Netscape 7 / Mozilla > 1.0)
But I am all confused on how to do this.

The reason I use [] for the checkbox name is because PHP can interpret that
directly as an array of value. But even if that can't be done, I'll be happy
with comma separated values as I can explode it easily into array in PHP.

Any help on this will be greatly appreciated. Thanks

Further more, is there any good tutorial on how to use javascript to access
the DOM elements? I used to do it the old way (like document.forms[0]. etc)
but I am not sure if that the recomended way anymore.

Thanks.

RDB


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list