2

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>

2
  • 1
    You're missing a semicolon at the end of line 3. Commented Jun 18, 2013 at 1:54
  • Also you should consider appending your table to a variable then calling document.write() once at the end of your script. It may improve performance and will make your script more flexible and appear cleaner. Commented Jun 18, 2013 at 2:11

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! that did it, Karthik my coworker? what a small world!
Oh My God ! Indeed a small world. See you tomorrow :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.