views:

283

answers:

1

How to change background color of row when I click the checkbox?

+1  A: 

You need a shot of Javascript for this.

<h:selectBooleanCheckbox onclick="highlightRow(this)">

with

function highlightRow(checkbox) {
    getParentByTagName(checkbox, 'tr').style.background = (checkbox.checked) ? '#6f6' : 'none';
}
function getParentByTagName(element, tagName) {
    var p = element.parentNode;
    return p ? ((p.tagName.toLowerCase() == tagName) ? p : getParentByTagName(p, tagName)) : false;
}

Or if you're already using jQuery:

function highlightRow(checkbox) {
    $(checkbox).closest('tr').css('background', checkbox.checked ? '#6f6' : 'none');
}
BalusC