![]() |
Change Table Row Colour with Checkbox onClick
Hello,
I think this may be a really simple task, but I'm no Javascript guru, so I'm having trouble grasping it. Google also wasn't much help, but probably because couldn't describe well enough what I wanted. Before I start, if anybody does reply and uses PrototypeJS, I also use it and a method using it would be much more preferred, but if not, normal Javascript will do. So I have this table set up... I'm not much of a table user, but using div's for this would just be too much hassle. Code:
<table width="100%" border="0" cellspacing="0" cellpadding="0">All I want to do, is when the checkbox is checked, I want the table row to change a different colour, and when unchecked, it will remove the colour... sounds simple huh? but I couldn't work my head around it... I mean I tried for ages and almost got it; I managed to change the colour of it, but when unchecked, it didn't remove it. Thanks for any help. |
Try this. Just set the
onclick() action on the checkboxes to call change_row_colour(this). Like so:Code:
onclick="change_row_colour(this)"javascript Code:
|
Cheers Wild Honey, I'll give it a shot and come back with a response.
|
Any luck with that, laddo?
|
Aye, much luck!
Thanks ya very muchly! Wish I knew what half of it meant, lol. What's parentNode and nodeName? |
Hehe. It's DOM so
parentNode would be the node above it. So if you have:Code:
<table>nodeName is simply its name, TR's node name is TR. Simple as that. |
I've just realised that this doesn't work in Internet Explorer... what's new eh?
I did a slight modification than the code Wildhoney provided: Code:
<script type="text/javascript">I hate IE sometimes... |
I have a question about this part:
Code:
pTarget.parentNode.parentNode Then using it later in the next line. Are you doing this just to shorten it so it wouldn't be so long like this? Code:
|
I changed the code a little bit, but it doesn't work for me?
Code:
<script type="text/javascript">Code:
<table width="796" border="1" cellspacing="5" cellpadding="2"> |
For your latest code, the
pTR variable isn't pointing to the table row, but to the label (first row) or td (other rows). It goes up two levels in the DOM tree, your HTML code needs it to traverse back four/three levels to reach the table row.Quote:
|
Quote:
Once I removed the label and the div's, it worked. |
| All times are GMT. The time now is 10:00 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0