faqts : Computers : Programming : Languages : JavaScript : DHTML

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

11 of 18 people (61%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I make a table so that when I click on a row, that whole row get selected?

Mar 13th, 2002 10:18
Matt McElheny, Kady Ny,


<html>
<body>
<script language="JavaScript">
var curSelected = null;
function rowClick(row)
{
	row.style.backgroundColor = 'blue';
	row.style.color = 'white';
	if (curSelected != null)
	{
		curSelected.style.backgroundColor = '';
		curSelected.style.color = '';
	}
	curSelected = row;
}
</script>
<table border="1">
<tr>
	<th>1</th>
	<th>2</th>
	<th>3</th>
</tr>
<tr onClick="rowClick(this)">
	<td>a1</td>
	<td>a2</td>
	<td>a3</td>
</tr>
<tr onClick="rowClick(this)">
	<td>b1</td>
	<td>b2</td>
	<td>b3</td>
</tr>
<tr onClick="rowClick(this)">
	<td>c1</td>
	<td>c2</td>
	<td>c3</td>
</tr>
</table>
</body>
</html>