Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row Highlighting

Status
Not open for further replies.

vikaskalra

Technical User
Aug 12, 2002
41
GB
Hi !

I am looking for some help from you experts on as to how can I highlight selective Rows. Say in a Table I have some check boxes and text. What I want to do is, when the User clicks a particular Checkbox, I want to change the Color, so one can easily distinguish.

Expecting a Quick response,
Thanks a Lot in Advance Friends,
Vikas
 
<table id=&quot;myTable&quot; cellspacing=&quot;0&quot;>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</table>


var table = document.getElementById(&quot;myTable&quot;);
var trs = table.getElementsByTagName(&quot;tr&quot;);

trs[1].style.backgroundColor = &quot;rgb(180, 180, 180)&quot;; Gary Haran
 
<script>
function highlight(chkbox, row, overColor, outColor) {
if (chkbox.checked)
document.getElementById(row).style.backgroundColor = overColor
else
document.getElementById(row).style.backgroundColor = outColor
}
</script>

. . .
<tr id=&quot;one&quot;>
<td><input type=&quot;checkbox&quot; onclick=&quot;highlight(this, 'one', '#ffffaa', '#ffffff')&quot;></td>
. . .

Function parameters are:
chkbox - checkbox (to determine if it's checked or not)
row - ID of the table row
overColor - &quot;highlighted&quot; color
outColor - &quot;normal&quot; state color

Works in all browsers except NN4.
 
Hey Guys,

Thanks for your quick response, it is really appreciated.

Vikas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top