lazyRascal
Programmer
Can anyone help me with some onLoad syntax?
The following code highlights the contents of a row in a table in my html page when clicked. It works when clicked.
I would like to have the first row selected automatically when the page is loaded. I've tried every way I can think of to execute it from within the <body> tag using the onLoad event. I can't get it to work. Any help would be greatly appreciated.
This snippet is just a striped down version of the actual code to demonstrate what I'm trying to accomplish; therefore, I'm not looking for alternative methods to get these results. I need to make this approach work, if possible.
I've used <body onLoad="javascript:'selected(0)'">. I think the problem is that I'm sending a value rather than an object.
I have the following code:
The following code highlights the contents of a row in a table in my html page when clicked. It works when clicked.
I would like to have the first row selected automatically when the page is loaded. I've tried every way I can think of to execute it from within the <body> tag using the onLoad event. I can't get it to work. Any help would be greatly appreciated.
This snippet is just a striped down version of the actual code to demonstrate what I'm trying to accomplish; therefore, I'm not looking for alternative methods to get these results. I need to make this approach work, if possible.
I've used <body onLoad="javascript:'selected(0)'">. I think the problem is that I'm sending a value rather than an object.
I have the following code:
Code:
<html>
<head>
<script language="JavaScript">
var curSelected = null;
function selected(row)
{
row.style.backgroundColor = 'cc7777';
row.style.color = 'white';
if (curSelected != null)
{
curSelected.style.backgroundColor = '';
curSelected.style.color = '';
}
curSelected = row;
}
</script>
</head>
<body>
<table border="0" cellpadding="3" cellspacing="0">
<tr onClick="selected(this)">
<td width=45><img src="hammer.jpg" height="60" border="2" style="border-color: #ffffff"></td>
<td>Hammer</td>
</tr>
<tr onClick="selected(this)">
<td width=45><img src="screwdriver.jpg" height="60" border="2" style="border-color: #ffffff"></td>
<td width='100'>Screwdriver</td>
</tr>
<tr onClick="selected(this)">
<td width=45><img src="pliers.jpg" height="60" border="2" style="border-color: #ffffff"></td>
<td>Pliers</td>
</tr>
</table>
</body>
</html>