[RESOLVED] reading from "array" values in JavaScript

wxdqz

New Member
I'm building a billing / shipping contact form, and I'm trying to copy the values from the FIRST set of billing address boxes to the first set of the shipping address. Here's my function:


var shipto_address[0] = "";
var shipto_city[0] = "";
var shipto_state[0] = "";
var shipto_stateIndex[0] = 0;
var shipto_zip[0] = "";
var shipto_country[0] = "";
var shipto_countryIndex[0] = 0;

function InitSaveFirstVariables(form) {
shipto_address[0] = form.shipto_address[0].value;
shipto_city[0] = form.shipto_city[0].value;
shipto_stateIndex[0] = form.shipto_state[0].selectedIndex;
shipto_state[0] = form.shipto_state[shipto_stateIndex][0].value;
shipto_zip[0] = form.shipto_zip[0].value;
shipto_countryIndex[0] = form.shipto_country[0].selectedIndex;
shipto_country[0] = form.shipto_country[shipto_countryIndex][0].value;
}
function ShipToFirstBillToAddress(form) {
if(form.copy_basic_billto_info.checked) {
InitSaveFirstVariables(form);
form.shipto_address[0].value = form.billto_address[0].value;
form.shipto_city[0].value = form.billto_city[0].value;
form.shipto_state[0].selectedIndex = form.billto_state[0].selectedIndex;
form.shipto_zip[0].value = form.billto_zip[0].value;
form.shipto_country[0].selectedIndex = form.billto_country[0].selectedIndex;
} else {
form.shipto_address[0].value = shipto_address[0];
form.shipto_city[0].value = shipto_city[0];
form.shipto_state[0].selectedIndex = shipto_stateIndex[0];
form.shipto_zip[0].value = shipto_zip[0];
form.shipto_country[0].selectedIndex = shipto_countryIndex[0];
}
}


I have used this same code w/o the [0]s in it, and it works like a champ. I need to keep the [0],[1],[2], etc. after each field name in my HTML form if at all possible so that I can read it in as an array in PHP before writing to the MySQL tables.
 
Top