Vynce82 Vynce82 - 3 years ago 71
HTML Question

Table generated in by Javascript not displaying

This table is not displaying in my html file: can anyone see an obvious mistake? I've been staring at it for hours!

<div id="data_list">
<script type="text/javascript">
document.write("<table border='1' rules='rows' cellspacing='0'>")
document.write("<tr>");
document.write("<th>Date</th><th>Amount</th><th>First Name</th>");
document.write("<th>Last Name</th><th>Address</th>");
document.write("</tr>");

for (i=0;i<=amount.length;i++){
if (i%2=0){
document.write(<tr>);
}else{
document.write("<tr class='yellowrow'>");
}

document.write("<td>" + date[i] + "</td class='amt'>" + amount[i]+ "</td>");
document.write("<td>" +firstName[i] + "</td><td>" + lastName[i] + "</td>");
document.write("<td>" + street[i] + "<br />" + city[i] + ", " +state[i]+ "" + zip[i] + "</td>");
document.write("</tr>");
}
document.write("</table>");
</script>



Answer Source

Here:

if (i%2=0){
    document.write(<tr>);
}else{
    document.write("<tr class='yellowrow'>");
}

should be

if (i%2==0){
    document.write('<tr>');
}else{
    document.write("<tr class='yellowrow'>");
}

i%2=0 should be i%2==0 Also, <tr> should be a string '<tr>'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download