...

View Full Version : change row color



nikko50
10-21-2005, 02:09 AM
Hi there. The following functions changes the row color. When the checkbox is clicked. How can I get rid of the color when the checkbox is unclicked??
<script>
function highlightRow (element, color) {
while (element.tagName.toUpperCase() != 'TR' && element != null)
element = document.all ? element.parentElement : element.parentNode;
if (element)
element.bgColor = color;
}
</script>
<table>
<tr>
<td width=100% id=\"tdID1\" ><input type='checkbox' ONCLICK=\"highlightRow(this, 'blue');\" class='normal2' name='request[]' value='$line[id]' ></td>

</tr></table>

gph
10-21-2005, 02:22 AM
function highlightRow (el, color) {
color=el.checked?color:'';
while (el.tagName.toUpperCase() != 'TR' && el != null)
el = el.parentNode;
if (el)
el.style.backgroundColor = color;
}

Kor
10-21-2005, 09:40 AM
onclick="this.parentNode.parentNode.style.backgroundColor=(this.checked)?'blue':''"

or, if you want a separate function

function highlightRow (el, color){
var oRow = el.parentNode.parentNode;
el.style.backgroundColor=(el.checked)?color:'';
}

nikko50
10-21-2005, 02:48 PM
The following functions works good to change the row color when the checkbox is clicked. How can I also change the checkbox border color within the same function??

<script>
function highlightRow (el, color) {
color=el.checked?color:'';
while (el.tagName.toUpperCase() != 'TR' && el != null)
el = el.parentNode;
if (el)
el.style.backgroundColor = color;
}
</script>
<input type='checkbox' ONCLICK="highlightRow(this, '#FF6F6F');" class='delete' name='delete[]' value='$line[id]' >

Kor
10-21-2005, 03:27 PM
try (not tested)

function highlightRow (el,col,bg){
var oRow = el.parentNode.parentNode;
oRow.style.backgroundColor=(el.checked)?color:'';
el.style.border=(el.checked)?'1px solid '+bg:'none';
}

...

onclick="highlightRow(this,'#FF6F6F','#FF0000')"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum