I am having an issue with a javascript generated table, which displays fine on the page, The div at the end (bottom_box) needs to have a custom class based on its html content. The code is below:
<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", "servicereport2.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
if (xmlDoc) {
var x = xmlDoc.getElementsByTagName("ISSUE");
for (i = 0; i < x.length; i++) {
document.write("<div class='box_lrg'><div class='box_top'></div><div class='box_middle'><table border='0'>");
document.write("<tr><td class='title'><h2>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</h2></td><td class='issueid'><strong>IssueID: </strong><br />");
document.write(x[i].getElementsByTagName("ISSUEID")[0].childNodes[0].nodeValue);
document.write("</td><td class='status'><strong>Status: </strong><br />");
document.write(x[i].getElementsByTagName("STATUSID")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
document.write("<tr><td colspan=3 class='description'>");
document.write(x[i].getElementsByTagName("TICKETDESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
document.write("<tr><td></td><td class='updated'><strong>Last Updated: </strong><br />");
document.write(x[i].getElementsByTagName("UPDATEDON")[0].childNodes[0].nodeValue);
document.write("</td><td class='author'><strong>Author: </strong><br />");
document.write(x[i].getElementsByTagName("AUTHOR")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
document.write("</table>");
document.write("</div><div class='box_bottom'>");
document.write(x[i].getElementsByTagName("CATEGORY")[0].childNodes[0].nodeValue);
document.write("</div></div>");
category = $('.box_bottom').html();
if (category == 'Notifications') {
$(".box_bottom").addClass("notifications");
}
category = $('.box_bottom').html();
if (category == 'VO')
{
$(".box_bottom").addClass("VO");
}
}
}
else {
document.write("<h3><span class='blue'>There are no issues at the moment.</span></h3>");
}
As you can see the JQuery is included in the loop, but is just applying the same class to all the bottom_box divs - they are all the first occurrence of the CATEGORY XML tag . EG if the first "category" is VO and the second is "notifications" then they are all being applied VO.
Any help is welcome.