PDA

View Full Version : Bug or simple solution?? Driving me crazy...



lindm
07-19-2008, 04:31 PM
Have a small anomaly which is driving me crazy.

The page is pretty much self-explaining...simply load in a browser or check: http://www.drlindmark.se/kevin/script.html





<head>
<style type="text/css" media="screen,print">
.checked {background-color: #F1F1F1;}

</style>
<script type="text/javascript">
function pl(name)
{
if (name.checked == true) {name.parentNode.parentNode.className = "checked";} else {name.parentNode.parentNode.className = "xxx";}
}

function plt(name)
{
if (name.checked == true) {name.parentNode.parentNode.parentNode.className = "checked";} else {name.parentNode.parentNode.parentNode.className = "xxx";}
}
</script>


</head>

<body>
<form name="form1" method="post" action="">
<table border="1" cellspacing="0" cellpadding="0" class="">
<tr>
<td width="355">Tableclass 1 - not checked and no class. Works fine.</td>
<td width="120">&nbsp;</td>
<td width="120">&nbsp;</td>
<td width="25">
<input type="checkbox" name="checkbox" id="checkbox" onclick="plt(this)"> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<table border="1" cellspacing="0" cellpadding="0" class="checked">
<tr>
<td width="355">Tableclass 2 - checked and class set.</td>
<td width="120">&nbsp;</td>
<td width="120">&nbsp;</td>
<td width="25">
<input name="checkbox" type="checkbox" id="checkbox" onclick="plt(this)" checked> </td>
</tr>
<tr>
<td><strong>PROBLEM!</strong> Why does not the background change??</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<table border="1" cellspacing="0" cellpadding="0">
<tr class="">
<td width="355">Rowclass 1 - not checked and no class. Works fine.</td>
<td width="120">&nbsp;</td>
<td width="120">&nbsp;</td>
<td width="25">
<input type="checkbox" name="checkbox2" id="checkbox2" onclick="pl(this)"> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<table border="1" cellspacing="0" cellpadding="0">
<tr class="checked">
<td width="355">Row class 2 - checked and class set. Works fine.</td>
<td width="120">&nbsp;</td>
<td width="120">&nbsp;</td>
<td width="25">
<input name="checkbox2" type="checkbox" id="checkbox2" onclick="pl(this)" checked> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
</form>

</body>
</html>

coothead
07-19-2008, 10:42 PM
Hi there lindm,

in your script...

name.parentNode.parentNode.parentNode.className
...refers to the tbody element not the table element. ;)
The solution to your problem is to either change the script to...

name.parentNode.parentNode.parentNode.parentNode.className
...or the html to...


<table border="1" cellspacing="0" cellpadding="0">
<tbody class="checked">
<tr>
<td width="355">Tableclass 2 - checked and class set.</td>
<td width="120">&nbsp;</td>
<td width="120">&nbsp;</td>
<td width="25">
<input name="checkbox" type="checkbox" id="checkbox" onclick="plt(this)" checked></td>
</tr><tr>
<td><strong>PROBLEM!</strong> Why does not the background change??</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

coothead

lindm
07-20-2008, 06:41 AM
Wonderful!

Many thanks

coothead
07-20-2008, 07:17 AM
No problem, you're welcome. ;)