faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 45 people (24%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I change the bgcolor of a <tr> when a checkbox has been selected, like hotmail now does?

Sep 18th, 2001 22:39
Gareth Hay, Jean-Bernard Valentaten, Daniel Ruiz,


If you are using IE, give the <tr> an id and simply change the bgcolor, 
or background attribute of it's style.
--
Well first off you have to find the <tr>. The best way to do so is to 
give it a stand-alone style using css (e.g. <tr class="specialTr">).
The style class would be defined like this:
<style>
  .specialTr {background-color: #FFFFFF;}
</style>
Then when you checkbox is selected you have it fire the onChange-
Handler somewhat like this:
<input type="checkbox" onChange="changeTr();">
Now you need a function to perform the changes. This can be a little 
tricky, since you need to search all the element in the document that 
have exactly that stylesheet-class etc.
I won't try to write some code here, since this would be an awfull lot 
of code.
Or you could also keep that stuff dynamic, somewhat like this:
function changeTr()
{
  document.write('<style>\n.stecialTr {background-color: #CCCCCC;}
\n</style>');
}
The \n are so called escape-sequences, that will just write a carriage-
return/line-feed.
HTH