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
Reply

Join Date: May 2007
Posts: 30
Reputation: akash_msrit is an unknown quantity at this point 
Solved Threads: 0
akash_msrit akash_msrit is offline Offline
Light Poster

help needed in coloring html tables

 
0
  #1
Jun 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help needed in coloring html tables

 
0
  #2
Jun 26th, 2007
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 30
Reputation: akash_msrit is an unknown quantity at this point 
Solved Threads: 0
akash_msrit akash_msrit is offline Offline
Light Poster

Re: help needed in coloring html tables

 
0
  #3
Jun 28th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help needed in coloring html tables

 
0
  #4
Jun 28th, 2007
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 30
Reputation: akash_msrit is an unknown quantity at this point 
Solved Threads: 0
akash_msrit akash_msrit is offline Offline
Light Poster

Re: help needed in coloring html tables

 
0
  #5
Jun 28th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help needed in coloring html tables

 
0
  #6
Jun 28th, 2007
  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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,193
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 162
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Sensei

Re: help needed in coloring html tables

 
0
  #7
Jun 28th, 2007
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>
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 30
Reputation: akash_msrit is an unknown quantity at this point 
Solved Threads: 0
akash_msrit akash_msrit is offline Offline
Light Poster

Re: help needed in coloring html tables

 
0
  #8
Jun 29th, 2007
hi
Thanks for your effort and spending time for me. I will try this now.

Thanks and Regards
Akash
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 30
Reputation: akash_msrit is an unknown quantity at this point 
Solved Threads: 0
akash_msrit akash_msrit is offline Offline
Light Poster

Re: help needed in coloring html tables

 
0
  #9
Jun 29th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 30
Reputation: akash_msrit is an unknown quantity at this point 
Solved Threads: 0
akash_msrit akash_msrit is offline Offline
Light Poster

Re: help needed in coloring html tables

 
0
  #10
Jun 29th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC