...

View Full Version : more array variables



rshandy
06-10-2004, 07:35 PM
Can anybody help me with defining variables with in a inner.HTML function et al that will change the name of the array:

i.e.

I have 2 arrays which are defined as follows

var prod= new array(10);
var clr= new array(10);

and let say...

prod[1]="$45";
prod[2]= "$85";
clr[1]="Red";
clr[2]="Blue";

I'd like to control the innerhtml function by using 2 variables say x and i.

for (i=1; i <= 2; i++) {
if (document.getElementById) {
document.getElementById(i).innerHTML = (x[i]);
x = x + 1;
}
}
.....

How can I get x[i] to actually represent the array value?

Thanks,

Rich

Mr J
06-10-2004, 08:09 PM
Do you mean something like this?

<div id="div1"></div>
<div id="div2"></div>

<script>

var prod= new Array(10);
var clr= new Array(10);

prod[0]="$45";
prod[1]= "$85";
clr[0]="Red";
clr[1]="Blue";

document.getElementById("div1").innerHTML =""

for(i=0;i<2;i++){
document.getElementById("div1").innerHTML += prod[i]+"<BR>"
document.getElementById("div2").innerHTML += clr[i]+"<BR>"
}

</script>

Kor
06-11-2004, 09:19 AM
or, if those two arrays are biunique linked, why not a double array?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum