Hightlight a row in a table when....

J

Jay

Hi !

I am writing a page that displays a list of records in a table. Each
row for each record. Each row has a checkbox associated with it. Does
anybody know how to highlight a row when I click on a checkbox in that
row and unhightlight it when I re-click that checkbox? (like in
"hotmail" and "yahoo" e-mail when u select a message to delete).


Any help would be appreciated !

Thank you in advance !

Jay
 
M

Martin Honnen

Jay said:
I am writing a page that displays a list of records in a table. Each
row for each record. Each row has a checkbox associated with it. Does
anybody know how to highlight a row when I click on a checkbox in that
row and unhightlight it when I re-click that checkbox? (like in
"hotmail" and "yahoo" e-mail when u select a message to delete).

Here is an example that traverses the document tree for a <tr> ancestor
element and then changes its inline background-color style as needed

<html lang="en">
<head>
<title>changing the background-color of a table row</title>
<script type="text/javascript">
var backgroundColor = 'lightblue';
function setRowBackground (childCheckbox) {
var row = childCheckbox.parentNode;
while (row && row.tagName.toLowerCase() != 'tr') {
row = row.parentNode;
}
if (row && row.style) {
if (childCheckbox.checked) {
row.style.backgroundColor = backgroundColor;
}
else {
row.style.backgroundColor = '';
}
}
}
</script>
<style type="text/css">
tr {
background-color: lightgreen;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td>
<label>
delete
<input type="checkbox" name="message" value="1"
onclick="setRowBackground(this);">
</label>
<td>
All for Kibology
</td>
</tr>

<tr>
<td>
<label>
delete
<input type="checkbox" name="message" value="2"
onclick="setRowBackground(this);">
</label>
<td>
Kibology for all
</td>
</tr>
</tbody>
</table>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top