| | |
help needed in coloring html tables
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2007
Posts: 30
Reputation:
Solved Threads: 0
hi,
i have a jsp page, in this page i am displaying data retrieved from mysql database. Now the problem is i must color table cell based on cell value. how to implement this.please give me an sample or working code foe this problem.( any code is accepted) preferably html or javascript.
i.e
if cell value is "late" then display that cell in red color
else
display the cell in green color
please help me.
Thanks ad Regards
Akash
i have a jsp page, in this page i am displaying data retrieved from mysql database. Now the problem is i must color table cell based on cell value. how to implement this.please give me an sample or working code foe this problem.( any code is accepted) preferably html or javascript.
i.e
if cell value is "late" then display that cell in red color
else
display the cell in green color
please help me.
Thanks ad Regards
Akash
Set the color property of text for the given td based on the value fetched from the tabe.
You can use normal conditional statements to do this work though it would be better if you use JSTL tags to do conditional branching.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
if value is 'late' <td style="color: red;">late</td> else <td style="color: green;">on time<td>
You can use normal conditional statements to do this work though it would be better if you use JSTL tags to do conditional branching.
I don't accept change; I don't deserve to live.
•
•
Join Date: May 2007
Posts: 30
Reputation:
Solved Threads: 0
hi
hello friends, i have problem here, please help me.
i have a jsp page in that jsp page i am displaying the data retrived from the database(mysql). i am displaying data in table format.
noe the problem is i want to color table cell based on cell value. that is if table cell consists value say "met" then i want to color that table cell in green color. like this for other cell.
first i want check the value and then select bgcolor for that cell accordingl .
i need working code for this . or sample code for checking condition in <td> tag.
this is the code i am using to display the data in html form
<table border="1" cellpadding="1" cellspacing="2">
<tr bgcolor="lightblue">
<th>Type </th>
<th WIDTH=40>IdNUM</th>
<th>ProdNum</th>
<th>SolID</th>
<th WIDTH=%200>Title</th>
<th>DevManager</th>
<th>Owner</th>
<th>Severity</th>
<th>Status</th>
<th>Analysis Due</th>
<th>Agoal</th>
<th>Pgoal</th>
<th>Igoal</th>
<th>Fgoal</th>
</tr>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:mmt","root","admin");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(
"select Type,idnum,ProdNum,SolID,Title,DevManager,Owner,Severity,Status,AnalysisDue,Agoal,Pgoal,Igoal,Fgoal from wmr where ( SolInDev > 5 AND AnalysisDone=' ' ) AND (IsExternal='y')");
try {
String bgColor = "silver";
while (rs.next()) {bgColor = bgColor.equals("silver") ? "white" : "silver";%>
<tr bgcolor="<%=bgColor%>">
<td align="center"><%= rs.getString("Type") %></td>
<td ><%= rs.getString("Idnum") %></td>
<td align="right" ><%= rs.getString("ProdNum") %></td>
<td align="right" ><%= rs.getString("SolId") %></td>
<td align="center"><%= rs.getString("Title") %></td>
<td align="center"><%= rs.getString("DevManager") %></td>
<td align="center"><%= rs.getString("Owner") %></td>
<td align="center"><%= rs.getString("Severity") %></td>
<td align="center"><%= rs.getString("status") %></td>
<td align="center"><%= rs.getString("AnalysisDue") %></td>
<td align="center"><%= rs.getString("Agoal") %></td>
<td align="center"><%= rs.getString("Pgoal") %></td>
<td align="center"><%= rs.getString("Igoal") %></td>
<td align="center"><%= rs.getString("Fgoal") %></td>
</tr>
<% }
rs.close();
conn.close();
}catch (Exception e) {
out.println("Exception: " + e.getMessage());
} %>
</table>
</body>
</html>
if pgoal value = "met" then change that cell color to green. i want this.
i think now u can provide me some code
thanks and regards
manjunath
hello friends, i have problem here, please help me.
i have a jsp page in that jsp page i am displaying the data retrived from the database(mysql). i am displaying data in table format.
noe the problem is i want to color table cell based on cell value. that is if table cell consists value say "met" then i want to color that table cell in green color. like this for other cell.
first i want check the value and then select bgcolor for that cell accordingl .
i need working code for this . or sample code for checking condition in <td> tag.
this is the code i am using to display the data in html form
<table border="1" cellpadding="1" cellspacing="2">
<tr bgcolor="lightblue">
<th>Type </th>
<th WIDTH=40>IdNUM</th>
<th>ProdNum</th>
<th>SolID</th>
<th WIDTH=%200>Title</th>
<th>DevManager</th>
<th>Owner</th>
<th>Severity</th>
<th>Status</th>
<th>Analysis Due</th>
<th>Agoal</th>
<th>Pgoal</th>
<th>Igoal</th>
<th>Fgoal</th>
</tr>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:mmt","root","admin");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(
"select Type,idnum,ProdNum,SolID,Title,DevManager,Owner,Severity,Status,AnalysisDue,Agoal,Pgoal,Igoal,Fgoal from wmr where ( SolInDev > 5 AND AnalysisDone=' ' ) AND (IsExternal='y')");
try {
String bgColor = "silver";
while (rs.next()) {bgColor = bgColor.equals("silver") ? "white" : "silver";%>
<tr bgcolor="<%=bgColor%>">
<td align="center"><%= rs.getString("Type") %></td>
<td ><%= rs.getString("Idnum") %></td>
<td align="right" ><%= rs.getString("ProdNum") %></td>
<td align="right" ><%= rs.getString("SolId") %></td>
<td align="center"><%= rs.getString("Title") %></td>
<td align="center"><%= rs.getString("DevManager") %></td>
<td align="center"><%= rs.getString("Owner") %></td>
<td align="center"><%= rs.getString("Severity") %></td>
<td align="center"><%= rs.getString("status") %></td>
<td align="center"><%= rs.getString("AnalysisDue") %></td>
<td align="center"><%= rs.getString("Agoal") %></td>
<td align="center"><%= rs.getString("Pgoal") %></td>
<td align="center"><%= rs.getString("Igoal") %></td>
<td align="center"><%= rs.getString("Fgoal") %></td>
</tr>
<% }
rs.close();
conn.close();
}catch (Exception e) {
out.println("Exception: " + e.getMessage());
} %>
</table>
</body>
</html>
if pgoal value = "met" then change that cell color to green. i want this.
i think now u can provide me some code
thanks and regards
manjunath
Last edited by akash_msrit; Jun 28th, 2007 at 7:19 am.
java Syntax (Toggle Plain Text)
<% String pGoal = rs.getString("pGoal"); if(pGoal.equals("met")) out.println("<td style='background-color: green;'>" + pGoal + "</td>") else out.println("<td style='background-color: red;'>" + pGoal + "</td>") %>
I would not recommend scriptlets but I don't think you care about it though...
Last edited by ~s.o.s~; Jun 28th, 2007 at 12:05 pm.
I don't accept change; I don't deserve to live.
Why not create a stylesheet class for each color?
.
Then just insert the correct classes when you put the values in the tables, either directly or through a script:
.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
.bred {background-color: red;} .bgrn {background-color: green;}
Then just insert the correct classes when you put the values in the tables, either directly or through a script:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<td class="bgrn">met</td>
Daylight-saving time uses more gasoline
•
•
Join Date: May 2007
Posts: 30
Reputation:
Solved Threads: 0
hi
Thanks for the reply,
the problem is here i am not inserting any values to the table. i am retreiving data from the database and displaying.
so i have to check what that cell conmtains .if that cell contains "met" then i want change the bgcolor of that cell to green. like that
can u help me now
Thnaks and Regards
akash
Thanks for the reply,
the problem is here i am not inserting any values to the table. i am retreiving data from the database and displaying.
so i have to check what that cell conmtains .if that cell contains "met" then i want change the bgcolor of that cell to green. like that
can u help me now
Thnaks and Regards
akash
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Opera Javascript bug? (works in Firefox)
- Next Thread: Inserting dynamic values into Javascript variables
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug captchaformproblem checkbox close codes createrange() css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n






