Click to See Complete Forum and Search --> : Accessing a transmitted array


mgoldbeck
09-26-2003, 06:06 PM
The specific array I[] was sent via "Form" as follows: document.write('<input type="hidden" name="I[] value=+I[i]+'">" . A variable "Total" was sent the same way. When I try to access I[0] on the desination document "order.htm" it fails. I'm using: Item0=document.order.I[0].value; When I use: totalHere=document.order.Total.value; to get the Total value, it works fine. I think I'm accessing I[] incorrectly. Anyone know how to do this?

Jona
09-26-2003, 06:20 PM
Do you have this online or an example to which I may "test"? If you do not, please provide a bit better explanation... How exactly are you sending this data from one page to the other? Via the GET method and parsing it via JavaScript?

[J]ona

mgoldbeck
09-26-2003, 07:48 PM
Unfortunately, I don't have anything online to show you. Here is the code that sends the array:

<script language="JavaScript">
function getInput() {
if ((Num!=null) && (Num>=0)) {
var Total=0;
var SHT=0;
var SHST=0;
for (var i=0; i<=Num; i++) {
P[i]=new Number(P[i])*new Number(Q[i]);
S[i]=new Number(S[i])*new Number(Q[i]);
SHT=SHT+(S[i]);
if (S[i]==0) SHST=SHST+P[i];
ST[i]=P[i]+S[i];
Total=Total+ST[i];
P[i]=Decimal(P[i]);
S[i]=Decimal(S[i]);
ST[i]=Decimal(ST[i]);
document.write('<input type="hidden" name="I[]" value="'+I[i]+'">\n');
document.write('<input type="hidden" name="Q[]" value="'+Q[i]+'">\n');
document.write('<input type="hidden" name="P[]" value="'+P[i]+'">\n');
document.write('<input type="hidden" name="S[]" value="'+S[i]+'">\n');
document.write('<input type="hidden" name="ST[]" value="'+ST[i]+'">\n');
document.write('<input type="hidden" name="U[]" value="'+U[i]+'">\n'); }
Total=Decimal(Total);
document.write('<input type="hidden" name="Total" value="'+Total+'">\n');
SHT=Decimal(SHT);
document.write('<input type="hidden" name="SHT" value="'+SHT+'">\n');
SHST=Decimal(SHST);
document.write('<input type="hidden" name="SHST" value="'+SHST+'">\n'); }}

document.write('<form method=\"POST\" name=\"Order\" action=\"'+SURL+'\" target=\"_top\">\n'); getInput()</script><input type="hidden" name="action"></form>

Jona
09-26-2003, 08:01 PM
You're naming them the same thing--try using document.write('<input type="hidden" name="'+I+'" value="'+I[i]+'">');

[J]ona

mgoldbeck
09-28-2003, 12:17 PM
Thanks for your suggestions. This didn't work, either. I tried a work around that also failed: I am able to access the "Total" variable after it is sent to "order", so I set up another variable "catOnly" and sent it to "order". I used exactly the same code to send "catOnly" as I use for "Total". And, I used exactly the same code to access "catOnly" as for "Total" and still "catOnly" is not accessable. Here is a portion of the function used to access "Total" (at bottom of code).
function Load() {
var Contact=GetCookie("contact");
var CS=new String(Contact);
var Contact_Field=CS.split("!!");
var Billing=GetCookie("billing");
var BS=new String(Billing);
var Billing_Field=BS.split("!!");
var charge=7;

//if((Item_Field[0]=="catalog") && (Item_Field.length==1)) charge=0;

if (Contact!=null) {
document.order.Contact_Name.value=Contact_Field[0];
document.order.Street_Address.value=Contact_Field[1];
document.order.City.value=Contact_Field[2];
document.order.State.value=Contact_Field[3];
document.order.Zip.value=Contact_Field[4];
document.order.Country.value=Contact_Field[5];
document.order.Telephone_Number.value=Contact_Field[6];
document.order.Email.value=Contact_Field[7];
document.order.Billing_Name.value=Billing_Field[0];
document.order.Billing_Address.value=Billing_Field[1];
document.order.Billing_City.value=Billing_Field[2];
document.order.Billing_State.value=Billing_Field[3];
document.order.Billing_Zip.value=Billing_Field[4];
document.order.Billing_Country.value=Billing_Field[5]; }
Sub_Total=document.order.Total.value;
catO=document.order.catOnly.value;

When I try to access "catOnly" I seem to get some kind of error that causes the function "Load" to crash. I get no error indication, however. Everything between "Total" and "catOnly" seems the same, but "catOnly" fails. I don't have enough understanding about what happens to data after it has been sent to another document through "Form" "Post".

Jona
09-28-2003, 01:30 PM
Try setting the variable Contact to what it should be in the cookie, then test it...

[J]ona

mgoldbeck
09-29-2003, 03:19 PM
I'm sorry if the code I sent was misleading, but the cookies referred to in this code actually have nothing to do with "Total" or "catOnly". These variables were sent (please refer to previous posts) as hidden name/value pairs in a Form to the "Order.htm" document. When a name/value pair is sent to another form, do you know where that data is stored while awaiting processing? Is it a part of the destination form? Or better still, do you know of a website that has detailed info regarding this? Thanks.

Jona
09-29-2003, 06:15 PM
The data is stored in variables... There are lots of good tutorial sites on the Internet... I'd try searching Google, since that's where I learned a lot of this stuff. :p Or buy yourself a good book (the JavaScript Bible by Danny Goodman). lol.

[J]ona

mgoldbeck
09-30-2003, 12:10 PM
Hey, thanks for your help.

Jona
09-30-2003, 12:12 PM
Well, I tried...

[J]ona