Click to See Complete Forum and Search --> : Array question


tomwoj
03-14-2005, 06:03 PM
I am trying to return a value from a 2 dimension array. Below is an example of what I'm trying to do. Does anyone know why it won't work?


array1[0][0] = "Some Text";
array1[0][1] = "document.forms[0].PersonName";

for (i=0; i<array1.length; i++){
array[i][1].style.background = "#FCC";
}


This is breaking on trying to appy the style to the form element.

thanks for any insight.

Exuro
03-14-2005, 06:21 PM
What you want to do is store a reference to an element in your array varaible. To do this, all you do is set your array variable equal to it, and it becomes a reference:
array1[0][0] = "Some Text";
// Notice the lack of quotation marks:
array1[0][1] = document.forms[0].PersonName;

for (i=0; i<array1.length; i++){
array[i][1].style.background = "#FCC";
}

tomwoj
03-14-2005, 08:54 PM
Thanks Exuro, I'm going to try it as soon as I get to work tomorrow.

Thanks Again.