944,022 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jun 26th, 2007
0

help needed in coloring html tables

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Light Poster
akash_msrit is offline Offline
30 posts
since May 2007
Jun 26th, 2007
0

Re: help needed in coloring html tables

Set the color property of text for the given td based on the value fetched from the tabe.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. if value is 'late'
  2. <td style="color: red;">late</td>
  3. else
  4. <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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006
Jun 28th, 2007
0

Re: help needed in coloring html tables

hi

thanks for the reply. i tried this but i am not able to achieve what i need. if u have any other alternate code please forward me.


Thanks and Regards
Manjunath.S
Reputation Points: 10
Solved Threads: 0
Light Poster
akash_msrit is offline Offline
30 posts
since May 2007
Jun 28th, 2007
0

Re: help needed in coloring html tables

I can churn out alternatives only if you provide me with the code you have so far. What I presented in my previous post was a fairly easy thing to have done. If you are not able to achieve it, post the most recent code.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006
Jun 28th, 2007
0

Re: help needed in coloring html tables

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
Last edited by akash_msrit; Jun 28th, 2007 at 7:19 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
akash_msrit is offline Offline
30 posts
since May 2007
Jun 28th, 2007
0

Re: help needed in coloring html tables

java Syntax (Toggle Plain Text)
  1. <%
  2. String pGoal = rs.getString("pGoal");
  3. if(pGoal.equals("met"))
  4. out.println("<td style='background-color: green;'>" + pGoal + "</td>")
  5. else
  6. out.println("<td style='background-color: red;'>" + pGoal + "</td>")
  7. %>

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,872 posts
since Jun 2006
Jun 28th, 2007
0

Re: help needed in coloring html tables

Why not create a stylesheet class for each color?
.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. .bred {background-color: red;}
  2. .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)
  1. <td class="bgrn">met</td>
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Jun 29th, 2007
0

Re: help needed in coloring html tables

hi
Thanks for your effort and spending time for me. I will try this now.

Thanks and Regards
Akash
Reputation Points: 10
Solved Threads: 0
Light Poster
akash_msrit is offline Offline
30 posts
since May 2007
Jun 29th, 2007
0

Re: help needed in coloring html tables

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
Reputation Points: 10
Solved Threads: 0
Light Poster
akash_msrit is offline Offline
30 posts
since May 2007
Jun 29th, 2007
0

Re: help needed in coloring html tables

i tried that java scrit but i am geetting some other problem. that is nothing is displayed in that coloumn 0r cell .
if possible please embed that javascript in my code.
if u give me ur mail id i will post some report in which i need.
Thanks and Regards
akash
Reputation Points: 10
Solved Threads: 0
Light Poster
akash_msrit is offline Offline
30 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Opera Javascript bug? (works in Firefox)
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Inserting dynamic values into Javascript variables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC