Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    58
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Post Color an id's value based on another id's value

    Hello,

    Could someone please help. I want to be able to color the value of an ID based on the value of another value. My script displays a table with a "stock symbol", the "last value", the "change in dollars" and the "change in percentage". The "direction" column will be removed later. I want to make the value of the "change in dollar" and "change in percentage" either red(if "-" direction value) or green(if "+" direction value). I hope this makes sense. Here is the code:

    Thanks!

    HTML:
    Code:
    <html>
    <body>
    <script type="text/javascript">
    var xmlDoc=null;
    if (window.ActiveXObject)
    {// code for IE
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    else if (document.implementation.createDocument)
    {// code for Firefox, Mozilla, Opera, etc.
    xmlDoc=document.implementation.createDocument("","",null);
    }
    else
    {
    alert('Your browser cannot handle this script');
    }
    if (xmlDoc!=null)
    {
    xmlDoc.async=false;
    xmlDoc.load("marketWatch.xml");
    document.write("<table border='1'>");
    document.write("<tr>");
    document.write("<td>");
    document.write("Symbol");
    document.write("</td>");
    document.write("<td>");
    document.write("Last");
    document.write("</td>");
    document.write("<td>");
    document.write("$Chg");
    document.write("</td>");
    document.write("<td>");
    document.write("%Chg");
    document.write("</td>");
    document.write("<td>");
    document.write("direction");
    document.write("</td>");
    document.write("</tr>");
    var x=xmlDoc.getElementsByTagName("stock");
    for (var i=0;i<5;i++)
    { 
    document.write("<tr>");
    document.write("<td>");
    document.write(x[i].getElementsByTagName("symbol")[0].childNodes[0].nodeValue);
    document.write("</td>");
    document.write("<td>");
    document.write(x[i].getElementsByTagName("value")[0].childNodes[0].nodeValue);
    document.write("</td>");
    document.write("<td>");
    document.write(x[i].getElementsByTagName("change")[0].childNodes[0].nodeValue);
    document.write("</td>");
    document.write("<td>");
    document.write(x[i].getElementsByTagName("percent")[0].childNodes[0].nodeValue);
    document.write("</td>");
    document.write("<td>");
    document.write(x[i].getElementsByTagName("direction")[0].childNodes[0].nodeValue);
    document.write("</td>");
    document.write("</tr>");
    }
    document.write("</table>");
    }
    </script>
    </body>
    </html>
    XML:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <stocks>
      <stock>
        <symbol>DJIA</symbol>
        <company>DOW JONES</company>
        <value>10,915.37</value>
        <change>109.50</change>
        <percent>1.01</percent>
        <direction>+</direction>
      </stock>
      <stock>
      <symbol>NASDAQ</symbol> 
      <company>NASDAQ</company> 
      <value>1,497.42</value> 
      <change>20.13</change> 
      <percent>1.36</percent> 
      <direction>+</direction> 
      </stock>
    <stock>
      <symbol>SP500</symbol> 
      <company>SP500</company> 
      <value>842.52</value> 
      <change>-10.57</change> 
      <percent>-1.27</percent> 
      <direction>-</direction> 
      </stock>
    <stock>
      <symbol>BK</symbol> 
      <company>BANK OF NEW YORK</company> 
      <value>24.23</value> 
      <change>0.35</change> 
      <percent>1.48</percent> 
      <direction>+</direction> 
      </stock>
    <stock>
      <symbol>FNM</symbol> 
      <company>FANNIE MAE</company> 
      <value>0.65</value> 
      <change>-0.02</change> 
      <percent>-2.99</percent> 
      <direction>-</direction> 
      </stock>
    </stocks>
    Last edited by bigalo; 01-26-2009 at 06:32 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •