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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Collect Javascript two dimensional Array in to <div>

    Hi All,

    Pls tell me if there is any way to collect the java script two dimension array elements in to a single <DIV> </Div> block.

    Thanks,
    V

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    could you clarify your question please?
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Brandon,

    I like to populate <div> </div> elements based on two dimensional array elements.

    array[0][0] = date;
    array[0][1] = url;
    array[0][2] = label

    would like to keep this code in side <body> </body> tags.

    Thanks,
    Vishnu P.

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    creat your div's, and give them an id, then use the body onload handler to populate. this is the only way to do it if your divs are in the body.
    here is an example:



    Code:
    <html>
    <head>
    
    </head>
    
    
    <body onload=populate()>
    <script type=text/javascript>
    function populate(){
    var info=new Array(4);//creates an array with 4 values
    for(i=0;i<info.length;i++){
    info[i]=new Array(3);//makes each value of info an array with 3 values
    }
    //fill in the values of the arrays here
    info[0][0]='label1';
    info[0][1]='url1';
    info[0][2]='date1';
    info[1][0]='label2';
    info[1][1]='url2';
    info[1][2]='date2';
    info[2][0]='label3';
    info[2][1]='url3';
    info[2][2]='date3';
    info[3][0]='label4';
    info[3][1]='url4';
    info[3][2]='date4';
    for(i=0;i<info.length;i++){
    var whattoinsert='';
    for(j=0;j<info[i].length;j++){
    whattoinsert+=info[i][j]+"<br>";
    
    }
    document.getElementById('div'+i).innerHTML=whattoinsert;
    }
    }
    </script>
    
    
    
    <div id=div0></div><br>
    <div id=div1></div><br>
    <div id=div2></div><br>
    <div id=div3></div><br>
    </body>
    
    
    </html>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

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