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.
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
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..
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 ...
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 - <html xmlns="http://www.w3.org/1999/xhtml">
-
<?php
-
$q=$_GET["q"];
-
-
$con = mysql_connect("localhost","xxx","xxx","xxx");
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
mysql_select_db("xxx", $con);
-
-
$sql="SELECT * FROM Fluids WHERE id = '".$q."'";
-
-
$result = mysql_query($sql);
-
-
echo "<table border='1'>
-
<tr>
-
<th>Nitrile</th>
-
<th>HBNR</th>
-
<th>EPDM</th>
-
<th>Fluorocarbon</th>
-
<th>Neoprene</th>
-
<th>SBR</th>
-
<th>Polyacrylate</th>
-
<th>Polyurethane</th>
-
<th>Butyl</th>
-
<th>Butadiene</th>
-
<th>Isoprene</th>
-
<th>NR</th>
-
<th>Hypalon</th>
-
<th>Fluorosilicone</th>
-
<th>Silicone</th>
-
<th>Image</th>
-
</tr>";
-
-
while($row = mysql_fetch_array($result))
-
{
-
echo "<tr align='center'>";
-
echo "<td>" . $row['Nitrile'] . "</td>";
-
echo "<td>" . $row['HNBR'] . "</td>";
-
echo "<td>" . $row['EPDM'] . "</td>";
-
echo "<td>" . $row['Neoprene'] . "</td>";
-
echo "<td>" . $row['SBR'] . "</td>";
-
echo "<td>" . $row['Polyacrylate'] . "</td>";
-
echo "<td>" . $row['Polyurethane'] . "</td>";
-
echo "<td>" . $row['Butyl'] . "</td>";
-
echo "<td>" . $row['Butadiene'] . "</td>";
-
echo "<td>" . $row['Isoprene'] . "</td>";
-
echo "<td>" . $row['NR'] . "</td>";
-
echo "<td>" . $row['Hypalon'] . "</td>";
-
echo "<td>" . $row['Fluorosilicone'] . "</td>";
-
echo "<td>" . $row['Silicone'] . "</td>";
-
// echo "<td>" . $row['Image'] . "</td>";
-
echo "</tr>";
-
}
-
echo "</table>";
-
-
mysql_close($con);
-
?>
-
</body>
-
</html>
Then the html / java page. get_user.html - <html>
-
<head>
-
<script type="text/javascript">
-
function showFluid(str)
-
{
-
if (str=="")
-
{
-
document.getElementById("txtHint").innerHTML="";
-
return;
-
}
-
if (window.XMLHttpRequest)
-
{// code for IE7+, Firefox, Chrome, Opera, Safari
-
xmlhttp=new XMLHttpRequest();
-
}
-
else
-
{// code for IE6, IE5
-
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
xmlhttp.onreadystatechange=function()
-
{
-
if (xmlhttp.readyState==4 && xmlhttp.status==200)
-
{
-
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
-
}
-
}
-
xmlhttp.open("GET","getuser.php?q="+str,true);
-
xmlhttp.send();
-
}
-
-
-
</script>
-
</head>
-
<body>
-
-
<form>
-
<select name="fluids" size="5" onChange="showFluid(this.value)"><br/>
-
<option value="1">1-Butene 2-Ethyl</option>
-
<option value="2">1-Chloro 1-Nitro Ethane</option>
-
<option value="3">AN-O-3 Grade M</option>
-
<option value="4">AN-O-6</option>
-
<option value="5">AN-VV-O-366b Hydr. Fluid</option>
-
<option value="6">ASTM Oil, No.1</option>
-
<option value="7">ASTM Oil, No.2</option>
-
<option value="8">ASTM Oil, No.3</option>
-
-
</select>
-
</form>
-
<br />
-
<div id="txtHint"> Here
-
</div>
-
-
</body>
-
</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.
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 ...
Thank you for the help! I think I have got it now.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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.
|
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...
|
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""...
|
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...
|
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...
|
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'"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |