• Post Reply Bookmark Topic Watch Topic
  • New Topic

Change row color of a an html table row in a JSP page.  RSS feed

 
Madi Meka
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a JSP page with a html table to display employee directory. This is scriptlet :


and then i display the table rows and columns for each employee object(PS: I know scriptlets are bad and obsolete but this is my first individual project.)

I would like to change the background color of certain rows based on value of one particular value(based on eachEmp.getManagerCode).

How can i achieve that by using javascript? I tried to call a js function by calling onload event on . But as I need to check for each row that is not the possible solution. I have not tried jquery yet as I am very new to jquery and I didnt quite understand how to do it in jquery.

Please help.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhavee Latha Meka wrote:I know scriptlets are bad and obsolete but this is my first individual project.)

Why would that matter? Why learn how to do things the wrong way when you are just starting out? That makes no sense.

How can i achieve that by using javascript?

Why would you try to use JavaScript? CSS is what is used to control style.

For the rows that you want highlighted, put a class on the element and use CSS to sect that class and style it accordingly.
 
Madi Meka
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response I am working on making my code better.
Could you please tell me how can I add CSS conditionally on a row?
This is how I am building each row based on each Employee object:



I would like to color the row differently only if the eachEmp.ManagerCode is 3 but not 1 and 2.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding a class is easy:



This assumes use of the EL. I will not condone continued use of scriptlets.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!