Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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>

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    or, if those two arrays are biunique linked, why not a double array?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •