Current location: Hot Scripts Forums » General Web Coding » JavaScript » checkbox onClick - tr bg change


checkbox onClick - tr bg change

Reply
  #1 (permalink)  
Old 05-18-05, 07:58 AM
yoyo yoyo is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
checkbox onClick - tr bg change

This changes the tr bg color when i click on the checkbox:
PHP Code:



<table>
<
tr id="yoyo">
<
td>
<
input type="checkbox" onClick="document.getElementById('yoyo').style.backgroundColor='#84C1DF';">
</
td>
<
td>TEST TEST</td>
<
td>TEST</td>
</
tr>
</
table
How can I change the tr bg color to #FFFFFF when i uncheck the box?
Reply With Quote
  #2 (permalink)  
Old 05-18-05, 08:29 AM
kjmatthews kjmatthews is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: Boston, MA
Posts: 134
Thanks: 0
Thanked 0 Times in 0 Posts
Since you are using Javascript to change the box color in the first place, I would recommend asking the Javascript community how to use Javascript to change it back.

Also, won't what you posted change the color of the whole table row (not just the checkbox)? I see that the answer is yes.

Anyway, I just googled a bit - I suppose you could have done that yourself - and found this at http://www.ozzu.com/ftopic22858.html:

Code:
//make a function to toggle the class given to the checkbox
//this would go in the <head> of your HTML document
<script type="text/javascript">
function toggle(box,theId) {
   if(document.getElementById) {
      var cell = document.getElementById(theId);
      if(box.checked) {
         cell.className = "on";
      }
      else {
         cell.className = "off";
      }
   }
}
</script>

<style type="text/css">
 /* now we define how these classes are styled */
 .on {background-color:#84C1DF;}
 .off {background-color:white;}
</style>
Then, to make it all work, you would write the checkboxes this way:

Code:
<tr id="yoyo">
 <td class="off" id="cell1">
  <input type="checkbox" onclick="toggle(this,'yoyo')">Yada Yada Yada
 </td>
</tr>
The Javascript folks might be able to give you a better answer.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Been looking everywhere, onclick text change Drip Script Requests 0 11-27-04 01:03 AM
Been looking everywhere, onclick text change Drip JavaScript 0 11-27-04 12:55 AM


All times are GMT -5. The time now is 10:47 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.