Can I make this highlight TR and not just TD?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can I make this highlight TR and not just TD?

Post by simonmlewis »

Code: Select all

<script type="text/javascript">
function check(it) {
  tr = it.parentElement.parentElement;
  tr.style.backgroundColor = (it.checked) ? "gold" : "white";
}
</script>
<form onsubmit="return false">
<table border width=100%>
<tr><td><input type="checkbox" onclick="check(this)"></td><td>testing!</td><td>testing!</td><td>testing!</td><td>testing!</td></tr>
</table>
When I click the box, it highlights only the TD cell it's in, not the whole row.

Any ideas why?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Can I make this highlight TR and not just TD?

Post by Celauran »

Highlights the whole row for me...
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can I make this highlight TR and not just TD?

Post by simonmlewis »

strange, does for me when raw...... will have to check my code.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can I make this highlight TR and not just TD?

Post by simonmlewis »

Code: Select all

echo "<tr><td align='center'><label><font style='font-size: 10px'>TICK TO<br/>CHOOSE</font><input type='checkbox' name='X1include' value='yes' onclick=\"check(this)\"></label></td><td><img src='/images/productphotos/small/$rowac->photoprimary' /> </td><td><div class='sectionhead' style='margin-top: 0px'>$rowac->title</div><b>Choose color of Grout:</b>
      <select name='X1itemcode'>";
      if ($rowac->size1 != '') { echo "<option value='$rowac->romancode1'>$rowac->size1</option>";}
      if ($rowac->size2 != '') { echo "<option value='$rowac->romancode2'>$rowac->size2</option>";}
      if ($rowac->size3 != '') { echo "<option value='$rowac->romancode3'>$rowac->size3</option>";}
      if ($rowac->size4 != '') { echo "<option value='$rowac->romancode4'>$rowac->size4</option>";}
      echo "</select><br/><b>Packs needed:</b> <input type='text' name='X1quantity' ";
      $amount = $row->amountgrout * $quantity; 
      echo "value='$amount' $row->amountgrout' size='5'> x &pound; $rowac->price1</td></tr>";
This is my row. The code at the top is the same as previously entered.
It will ONLY highlight the TD.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can I make this highlight TR and not just TD?

Post by simonmlewis »

Damn - it's the <label>.
I need that to make it easier to tick, BUT, take it off and this script works.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply