You're mixing things up. First of all, you're passing a string in the on method, not a parameter:
should be:
Further, try to stay away from reserved words. On and id sound reserved to me:
Code:
function SetBackground(tableId)
is less likely to cause conflicts.
Next,
Code:
var action = document.getElementById('id');
gets a
reference to an object in the page called id. So, after this statement, action contains a reference to an
object, not just a simple
string. Again, action sounds like a reserved word, so it's probably better to change it.
Next, you *are* setting the background of the document, so I am not surprised the document changes and not the table:
Code:
document.bgColor = 'RED';
With this code you are setting the HTML bgcolor attribute to Red.
I suggest you change it all to something like this:
Code:
function SetBackground(tableId)
{
var theTable = document.getElementById(tableId);
theTable.style.backgroundColor = 'Red';
}
Combined with the following HTML markup, things will work as expected:
Code:
<table width="100%" border="1" id="MyTable">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="button" onclick="SetBackground('MyTable');" value="Click to change Color" />
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to:
Daydreaming by
Massive Attack (Track 7 from the album:
Blue Lines)
What's This?