...

View Full Version : Collect Javascript two dimensional Array in to <div>



vabh
06-07-2007, 01:51 AM
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

brandonH
06-07-2007, 01:53 AM
could you clarify your question please?

vabh
06-07-2007, 06:26 PM
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.

brandonH
06-09-2007, 01:18 AM
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:






<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum