faqts : Computers : Programming : Languages : JavaScript : Tables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 23 people (83%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I change the bgcolor of a <tr> when a checkbox has been selected, like hotmail now does?

Jul 31st, 2001 05:56
Lisa Persson, Ravi Yalamarthy,


I solved it this way (only IE4+): 
Comment: The checkbox elements name is a substring of the <tr> elements 
id.
<html>
<head>
<script>
function chooserow(chk, color) {
	if (document.all) {
		//IE4+
		if (chk.checked) {
			document.all.item('r' + chk.name).bgColor = 
color;	
		}
		else {
			document.all.item('r' + chk.name).bgColor = 
document.bgColor;
		}
	}
}
</script>
</head>
<body>
<form name="form1">
  <table border="0" cellspacing="0">
    <tr id = "r1"> 
      <td><input type="checkbox" name="1" onclick = "chooserow
(this, 'red');"></td>
      <td width="14%">test1</td>
      <td width="13%">test2</td>
      </tr>
    <tr id = "r2"> 
      <td><input type="checkbox" name="2" onclick = "chooserow
(this, 'red');"></td>
      <td width="14%">test3</td>
      <td width="13%">test4</td>
    </tr>
  </table>
</form>
</body>
</html>