Click to See Complete Forum and Search --> : Any way to dynamically write a table's bgcolor?


bunner bob
01-01-2003, 05:47 PM
Is there a way to access the bgcolor attribute of a table in order to change it dynamically?

I tried giving the table an ID:

<table ID="proxytable" width="450" border="1" cellpadding="0" cellspacing="0" bgcolor="#FFFF33">

And then addressing it using getElementById:

function setBackground(color) {
document.getElementById("proxytable").bgcolor = color;
}

or

function setBackground(color) {
document.getElementById("proxytable").bgcolor.value = color;
}

and - nada. Any suggestions?

gil davis
01-01-2003, 06:25 PM
Any suggestions?
Instead of guessing, you could take a tutorial, or read a book. ;-)

document.getElementById("proxytable").style.backgroundColor = color;

Assuming your browser is IE 5+, NS 6+ or Mozilla.

bunner bob
01-01-2003, 08:05 PM
Very good - thanks.

If either of the books I have had decent indexes I would have found it. Both have mention of backgroundColor and style but don't get specific enough to help me figure this out.

So in this case, instead of guessing, taking a tutorial or reading a book, I can post a question here and hope someone who's been down this road can help me - you have, so thanks! ;)

jdavia
01-01-2003, 09:56 PM
Is thih what you are looking for?. If so, you can make the mouseover a click, if you want.

<TABLE width="100%" border="1" cellspacing="0" cellpadding="2" table onMouseover="changeto('#')" onMouseout="changeback('white')">
<TR>
<!-- Row 1 Column 1 -->
<td id= "ignore" onmouseover="bgColor='lightgreen'" onmouseout="bgColor='#FFFFFF'" bgcolor="#FFFFFF" width="50%" align="center" valign="center">
<font color="green" >Change to Green</font></td>
<!-- Row 1 Column 2 -->
<td id="ignore"bgcolor="#FFFFFF" width="50%" align="center" valign="center"><font color="#D5D5D5"><font color=#ff0000>No Color Change</font>
<br> </td>
</TR>
</TABLE><BR>
<pre>
Directions:
To exclude any cell(s) from the rollover effect,
simply give that cell an id="ignore"declaration,
inserted inside the <td> tag. For example: <br>
&lt;table onMouseover=.... onMouseout=... &gt;
<b> <font size="+2">&lt;td id="ignore"&gt;Main Menu&lt;/td&gt;
</font></b>
</pre>

bunner bob
01-01-2003, 10:28 PM
Are those changeto() and changeback() predefined javascript functions? Or did you just not include them in your post.

If your script does what I think it does, you could do some pretty cool stuff with it I think. Gil Davis' suggestion did get me where I needed to be, but I'm intrigued by your post.

jdavia
01-02-2003, 12:48 AM
Are those changeto() and changeback() predefined javascript functions? Or
did you just not include them in your post. [QUOTE]

No anything or nothing can be inserted there.

pyro
01-02-2003, 09:40 AM
Originally posted by jdavia
No anything or nothing can be inserted there.

If you insert nothing, it will cause an error. If you are not going to have it call functions, remove them.