troubleshooting Question

Change td color dynamically

Avatar of Johny Bravo
Johny Bravo asked on
HTMLJavaScript
4 Comments1 Solution925 ViewsLast Modified:
Hi Experts,

I am creating a table from XML file with the help of Javascript.
Now I have a color attribute in my XML,and I want to set that color to the TD,where I am setting status.
//adding to the table
          var xmlDoc=null;
                if (window.ActiveXObject)
                {// code for IE
                xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                }
                else if (document.implementation.createDocument)
                {// code for Mozilla, Firefox, Opera, etc.
                xmlDoc=document.implementation.createDocument("","",null);
                }
                else
                {
                alert('Your browser cannot handle this script');
                }
                if (xmlDoc!=null)
                {
                xmlDoc.async=false;
                xmlDoc.load("ShipmentStat.xml");
 
                document.write("<table border='1' cellpadding='0'  cellspacing='0'>");
 
                var x=xmlDoc.getElementsByTagName("_x0040_Shipments");
for (i=0;i<x.length;i++)
                { 
                        
                document.write("<tr onMouseOut=\"this.className='normal'\"  onmouseover=\"this.className='highlight'\" border-bottom-color:'Black;' id='" + i + "'  onclick='trClick(this);'>"); 
                
                //document.write("<tr>");
                
                document.write("<td width ='200px'    >");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                x[i].getAttribute("Status"));
                document.write("</td>");
 
                document.write("<td width ='300px'>");
                document.write(
                x[i].getAttribute("Carrier"));
                document.write("</td>");
                                
                 document.write("<td width ='350px'>");
                document.write(
                x[i].getAttribute("Origin_x0020_Address"));
                document.write("</td>");
                                
                 document.write("<td width ='350px'>");
                document.write(
                x[i].getAttribute("Destination_x0020_Address"));
                document.write("</td>");
                                 
                   document.write("<td width ='150px'>");
                document.write(
                x[i].getAttribute("Pickup_x0020_Date_x002F_Time"));
                document.write("</td>");
               
                   document.write("<td width ='150px'>");
                document.write(
                x[i].getAttribute("Delivery_x0020_Date_x002F_Time"));
                document.write("</td>");
                               
                   document.write("<td width ='100px'>");
                document.write(
                x[i].getAttribute("Equipment"));
                document.write("</td>");
                document.write("</tr>");
                }
                document.write("</table>");
                }
                //end adding table
                           </script>
 
 
here is the sample XML
<markers>
  <_x0040_Shipments Status="In-Transit[Delayed]" Color="brown" Origin_x0020_Address="1465 sunset hills road  Herndon,VA 20190" Latitude="38.9582" Longitude="-77.3418" Destination_x0020_Address="dublin dr  Lakewood,CA 90712" _x0020_Latitude="33.8489" _x0020_Longitude="-118.147" Carrier="Averitt Express Inc" Equipment="Dry Van" Pickup_x0020_Date_x002F_Time="03/09/2009 7:15 AM" Delivery_x0020_Date_x002F_Time="03/10/2009 7:30 AM" Miles="3615" ShipmentID="47" OriginLocId="190" DestLocId="233" Carrierid="24" equipid="1" />
  <_x0040_Shipments Status="Delivered[Delayed]" Color="yellow" Origin_x0020_Address="11465 Sunset Hills Road #400 REston,VA 20190" Latitude="38.9582" Longitude="-77.3418" Destination_x0020_Address="Add111  Herndon,VA 20170" _x0020_Latitude="38.9812" _x0020_Longitude="-77.3873" Carrier="ABF Systems" Equipment="Dry Van" Pickup_x0020_Date_x002F_Time="03/08/2009 8:00 AM" Delivery_x0020_Date_x002F_Time="03/10/2009 8:15 AM" Miles="3" ShipmentID="46" OriginLocId="72" DestLocId="96" Carrierid="19" equipid="1" />
  <_x0040_Shipments Status="" Color="yellow" Origin_x0020_Address="  Herndon,VA 20190" Latitude="38.9582" Longitude="-77.3418" Destination_x0020_Address="134 st l Rd  Crescent,MO 63025" _x0020_Latitude="38.51" _x0020_Longitude="-90.6428" Carrier="FedEx Freight" Equipment="ERTYII" Pickup_x0020_Date_x002F_Time="01/27/2009 7:00 AM" Delivery_x0020_Date_x002F_Time="01/27/2009 7:15 AM" Miles="0" ShipmentID="45" OriginLocId="221" DestLocId="131" Carrierid="27" equipid="14" />
  <_x0040_Shipments Status="" Color="yellow" Origin_x0020_Address="265 Clyde Morris Boulevard  Ormond Beach,FL 32174" Latitude="29.29" Longitude="-81.1238" Destination_x0020_Address="11465 sunset hills road  Reston,VA 20190" _x0020_Latitude="38.9582" _x0020_Longitude="-77.3418" Carrier="BAYOU STATE TRANSPORTATIO" Pickup_x0020_Date_x002F_Time="12/30/2008 8:45 AM" Delivery_x0020_Date_x002F_Time="01/10/2009 9:45 AM" Miles="1095" ShipmentID="44" OriginLocId="98" DestLocId="173" Carrierid="8" equipid="550" />
  <_x0040_Shipments Status="In-Transit[On time]" Color="gray" Origin_x0020_Address="265 Clyde Morris Boulevard  Ormond Beach,FL 32174" Latitude="29.29" Longitude="-81.1238" Destination_x0020_Address="11465 Sunset Hills Road #400 REston,VA 20190" _x0020_Latitude="38.9582" _x0020_Longitude="-77.3418" Carrier="FedEx Freight" Equipment="Dry Van" Pickup_x0020_Date_x002F_Time="12/18/2008 7:30 AM" Delivery_x0020_Date_x002F_Time="12/18/2008 7:30 AM" Miles="20" ShipmentID="43" OriginLocId="98" DestLocId="72" Carrierid="27" equipid="1" />
</markers>
ASKER CERTIFIED SOLUTION
gmrsecs

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros