473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can I change the Cell Color based off of a number in it?

I'm trying to figure out the best way to deal with this problem. I have a select box that populates a table cells using Java / PHP.

That data that is then returned to the cells is always a number. What I would like to do is color code those cells based off the number that is returned.

I have search quit a bit for an answer but unable to find a solution on how to accomplish this. There is a ton of help for mouseover,out, onclick etc.. but that isn't what I need.

Any help is greatly appreciated.
May 14 '10 #1
6 3010
gits
5,390 Expert Mod 4TB
is the table prepared (filled) serverside or do you request the results with an ajax-call? basically you would just need to assign a css to the cells according to the cells-content ... but in those mentioned cases two different solutions would be appropriate ...

kind regards
May 15 '10 #2
results are requested with an ajax call. There is a select box with fluids, then a display table with the results. You can see what I mean here..
May 15 '10 #3
gits
5,390 Expert Mod 4TB
since you deliver readymade html you would just need to apply a specific css for a tablecell serverside when you create the response ...
May 15 '10 #4
thank you, I really have no idea where to start with that. I'm getting results, then I need to change the color of a cell based on those results. Is this a PHP issue or a Java issue. Here is the code I've wrote so far.

getuser.php
Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <?php
  3. $q=$_GET["q"];
  4.  
  5. $con = mysql_connect("localhost","xxx","xxx","xxx");
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10. mysql_select_db("xxx", $con);
  11.  
  12. $sql="SELECT * FROM Fluids WHERE id = '".$q."'";
  13.  
  14. $result = mysql_query($sql);
  15.  
  16. echo "<table border='1'>
  17. <tr>
  18. <th>Nitrile</th>
  19. <th>HBNR</th>
  20. <th>EPDM</th>
  21. <th>Fluorocarbon</th>
  22. <th>Neoprene</th>
  23. <th>SBR</th>
  24. <th>Polyacrylate</th>
  25. <th>Polyurethane</th>
  26. <th>Butyl</th>
  27. <th>Butadiene</th>
  28. <th>Isoprene</th>
  29. <th>NR</th>
  30. <th>Hypalon</th>
  31. <th>Fluorosilicone</th>
  32. <th>Silicone</th>
  33. <th>Image</th>
  34. </tr>";
  35.  
  36. while($row = mysql_fetch_array($result))
  37.   {
  38.   echo "<tr align='center'>";
  39.   echo "<td>" . $row['Nitrile'] . "</td>";
  40.   echo "<td>" . $row['HNBR'] . "</td>";
  41.   echo "<td>" . $row['EPDM'] . "</td>";
  42.   echo "<td>" . $row['Neoprene'] . "</td>";
  43.   echo "<td>" . $row['SBR'] . "</td>";
  44.   echo "<td>" . $row['Polyacrylate'] . "</td>";
  45.   echo "<td>" . $row['Polyurethane'] . "</td>";
  46.   echo "<td>" . $row['Butyl'] . "</td>";
  47.   echo "<td>" . $row['Butadiene'] . "</td>";
  48.   echo "<td>" . $row['Isoprene'] . "</td>";
  49.   echo "<td>" . $row['NR'] . "</td>";
  50.   echo "<td>" . $row['Hypalon'] . "</td>";
  51.   echo "<td>" . $row['Fluorosilicone'] . "</td>";
  52.   echo "<td>" . $row['Silicone'] . "</td>";
  53.  // echo "<td>" . $row['Image'] . "</td>";
  54.   echo "</tr>";
  55.   }
  56. echo "</table>";
  57.  
  58. mysql_close($con);
  59. ?> 
  60. </body>
  61. </html>
Then the html / java page. get_user.html
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function showFluid(str)
  5. {
  6. if (str=="")
  7.   {
  8.   document.getElementById("txtHint").innerHTML="";
  9.   return;
  10.   }
  11. if (window.XMLHttpRequest)
  12.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  13.   xmlhttp=new XMLHttpRequest();
  14.   }
  15. else
  16.   {// code for IE6, IE5
  17.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  18.   }
  19. xmlhttp.onreadystatechange=function()
  20.   {
  21.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  22.     {
  23.     document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  24.     }
  25.   }
  26. xmlhttp.open("GET","getuser.php?q="+str,true);
  27. xmlhttp.send();
  28. }
  29.  
  30.  
  31. </script>
  32. </head>
  33. <body>
  34.  
  35. <form>
  36. <select name="fluids" size="5" onChange="showFluid(this.value)"><br/>
  37. <option value="1">1-Butene 2-Ethyl</option>
  38. <option value="2">1-Chloro 1-Nitro Ethane</option>
  39. <option value="3">AN-O-3 Grade M</option>
  40. <option value="4">AN-O-6</option>
  41. <option value="5">AN-VV-O-366b Hydr. Fluid</option>
  42. <option value="6">ASTM Oil, No.1</option>
  43. <option value="7">ASTM Oil, No.2</option>
  44. <option value="8">ASTM Oil, No.3</option>
  45.  
  46. </select>
  47. </form>
  48. <br />
  49. <div id="txtHint"> Here
  50. </div>
  51.  
  52. </body>
  53. </html> 
I understand how to make a CSS but not sure how to switch styles based off of the results. Any help or reference you can provide I would really appreciate.
May 15 '10 #5
gits
5,390 Expert Mod 4TB
JavaScript has nothing to do with Java ... those are completely different things.

the easiest way would be to echo an additional style for a tablecell in your php-script ... just do that conditionally depending on your requirements ...
May 15 '10 #6
Thank you for the help! I think I have got it now.
May 15 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Scott | last post by:
In the result of a SELECT statement, how can you change cell values from NULL to BLANK? The following does NOT do it: SET fieldname = ' ' WHERE fieldname IS NULL Also, for colums with a DATE...
0
by: Andrea | last post by:
Hi everyone. I'm working on a navigation menu (in a frameset) that I want to set the "active" link to black (the link that corresponds to the page displayed in the right side of the frame) to...
31
by: Chris Stanley | last post by:
I am using dreamweaver to make an ASP page. I have a table of data from a MSSQL database that is currently showing on the ASP page. I want the ability to change the color based on a priority...
3
by: Erald Kulk | last post by:
L.S. in a datagrid I would like the forecolor of a single cell. Because it is a negative number. This cannot be done by changing the NumberFormat property. So how can I do this?? Erald
3
by: VB Programmer | last post by:
How do you change the background/fg color of a cell when the mouse is hovered above it? Examples would be nice.
5
by: DavidB | last post by:
Greetings I don't know if this is possible, but this group should be able to tell me. I have a webpage with a changing message board (I understand the problems with having changing text, but...
5
by: pplers | last post by:
Why can't i do this: <html> <body> <pre><center> <table border=2><tr><td onmouseover="bgcolor="red"" onclick="bgcolor="blue"" onkeyup="bgcolor="brown""...
2
by: pplers | last post by:
I'd like to know if there's a way to make the color of a cell/button change using onMouseOver. Is there some sort of "built-in" function to do this ? Thank you.... p.s: If possible, the...
5
by: patsman77 | last post by:
Hello All, I have been working on a little script, I am at a slight problem and was hoping for a little assistance. I am trying to change the color of a cell in my table based on a value...
1
by: nsteiner | last post by:
Hi all On my web page I have a 3 column table. The first cell changes background color when mouseover event occurs. Something like this : <TR><TD onMouseOver="this.bgColor='#00CC00'"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.