jasrasr
06-18-2009, 02:29 PM
I am trying to increase the variable by one each time the loop is printed.
<code>
function horsetable(hid1,hid2,hid3,hid4)
{
document.write("<table border=1>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid1[x]+"</td>"); } document.write ("</tr>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid2[x]+"</td>"); } document.write ("</tr>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid3[x]+"</td>"); } document.write ("</tr>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid4[x]+"</td>"); } document.write ("</tr>");
document.write ("</table>");
}
horsetable(id22511,id21111,id21112,id21131);
</code>
This only show 4, but I have 18 for this particular set.
I think I can combine all that into a for loop as such
<code>
for (var i=0,i<4;i++)
{
document.write ("<tr>");
for (var x=0;x<5;x++)
{
document.write ("<td>"+hid[i][x]+"</td>");
}
document.write ("</tr>");
}
</code>
Also is there an easier way to print this out without all the document.write's?
<code>
function horsetable(hid1,hid2,hid3,hid4)
{
document.write("<table border=1>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid1[x]+"</td>"); } document.write ("</tr>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid2[x]+"</td>"); } document.write ("</tr>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid3[x]+"</td>"); } document.write ("</tr>");
document.write ("<tr>"); for (var x=0;x<5;x++) { document.write ("<td>"+hid4[x]+"</td>"); } document.write ("</tr>");
document.write ("</table>");
}
horsetable(id22511,id21111,id21112,id21131);
</code>
This only show 4, but I have 18 for this particular set.
I think I can combine all that into a for loop as such
<code>
for (var i=0,i<4;i++)
{
document.write ("<tr>");
for (var x=0;x<5;x++)
{
document.write ("<td>"+hid[i][x]+"</td>");
}
document.write ("</tr>");
}
</code>
Also is there an easier way to print this out without all the document.write's?