-1

I have code that loops through and displays through document.write. I want to limit the display to 3 columns, but unlimited rows. I will past the code code below, but basically, the space I have to work with is the width of 3 columns but I have more than 3 columns of data. So I want the loop to stop at 3 and continue on the next row, but have unlimited rows. Code pasted here:

enter code here

<script type="text/javascript">
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "/_SHARED/ApplicationData/Public/FlashWriter.aspx?RotatorGroupID=5357", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var x = xmlDoc.getElementsByTagName("jpg");


document.write("<table border='0' width='675' cellspacing='0' cellpadding='0'>");

document.write("<tr>");

for (i = 0; i < x.length; i++) {

    document.write("<td><table border='0' cellspacing='0' cellpadding='0' id='static' ><tr><td class='HOT969' colspan='3'><a href='");
    document.write(x[i].attributes.getNamedItem("link").value);
    document.write("'><img width='190' height='125' class='image' src='");
    document.write(x[i].attributes.getNamedItem("image").value);
    document.write("'><br><div class='head'>");
    document.write(x[i].attributes.getNamedItem("head").value);
    document.write("</div><div class='copy'>");
    document.write(x[i].attributes.getNamedItem("desc").value);
    document.write("</div></a></td></tr></table></td>");
}

document.write("</tr>");

document.write("</table>");

Thanks in advance

DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
D-Dawgg
  • 117
  • 1
  • 2
  • 9

1 Answers1

0

You need another incrementer inside the block of your for loop.

Like so:

e = e++;

Or, you could wrap your for loop in a while loop, make that one the infinite one, and make the for loop stop at 3.

Like so:

var e = 0;
while (e < x.length){
for (i = 0; i < 3; i++) {
e = e + 1;
document.write("<td><table border='0' cellspacing='0' cellpadding='0' id='static' ><tr>
<td class='HOT969' colspan='3'><a href='");
document.write(x[i].attributes.getNamedItem("link").value);
document.write("'><img width='190' height='125' class='image' src='");
document.write(x[i].attributes.getNamedItem("image").value);
document.write("'><br><div class='head'>");
document.write(x[i].attributes.getNamedItem("head").value);
document.write("</div><div class='copy'>");
document.write(x[i].attributes.getNamedItem("desc").value);
document.write("</div></a></td></tr></table></td>");
}
}

document.write("</tr>");

document.write("</table>");
tjons
  • 4,749
  • 5
  • 28
  • 36