Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-10-2004, 07:35 PM   PM User | #1
rshandy
New to the CF scene

 
Join Date: Jun 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rshandy is an unknown quantity at this point
more array variables

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
rshandy is offline   Reply With Quote
Old 06-10-2004, 08:09 PM   PM User | #2
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
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>
Mr J is offline   Reply With Quote
Old 06-11-2004, 09:19 AM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
or, if those two arrays are biunique linked, why not a double array?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:36 PM.


Advertisement
Log in to turn off these ads.