Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a <TD> background color dynamicaly

Status
Not open for further replies.

onirike

Programmer
Aug 3, 2000
91
CA
Hi!

I am sure that question was already asked (I tried the search engine and I was not find the answer) so sorry to re-ask it again.

I have a <TD> defined like this:
<TD WIDTH=&quot;20&quot; ROWSPAN=&quot;2&quot; ALIGN=&quot;center&quot; ID=&quot;test&quot; STYLE=&quot;background: Red;&quot;>

And I want to be able on an onClick event to change the TD background color.

I tried this:
<A onClick=&quot;test.background=003399;&quot;>

It's not giving me any error but the background color is not changing...

Please help me fix this...
Thanks...
Chris ;-)
 
this works in ie.

<a href=&quot;#&quot; onClick=&quot;test.style.backgroundColor = '#003399';&quot;>dsfsddsf</a>
 
Hi Lucid!

I tried that and it keeps telling me that test.style is not an object. I am using IE 5.0. I dont need this to work with Netscape.

Complete part of code:
<TR>
<TD WIDTH=&quot;20&quot; ROWSPAN=&quot;2&quot; ALIGN=&quot;center&quot; ID=&quot;test&quot; STYLE=&quot;background: Red;&quot;> </TD>
<TD WIDTH=&quot;160&quot; ID=&quot;test2&quot; STYLE=&quot;background: Red;&quot; ROWSPAN=2 ALIGN=&quot;RIGHT&quot;>
<font face=&quot;arial&quot; size=&quot;2&quot; COLOR=&quot;003399&quot;><B><A onClick=&quot;test.style.backgroundColor='##003399';&quot;>Something here</A></FONT>
</TR>
 
<A href=&quot;#&quot; onClick=&quot;test.style.backgroundColor='#003399';&quot;>Something here</A>


use this
 
Hi Lucid!
I really appreciate your help!

I tried it and it's giving me the same error.
That's really strange... I am reading the MSDN help and they are saying the exact same thing that you are...

I really dont know why it's not working.

Thx,
Chris ;-)
 
If this feature is really necessary, then it could be programmed
by an image map: Don´t use a background color
but a background image, which is a 1x1 pixel GIF, blown up
by repetition. A click on the imagemap-area should load a new
page with a new background image (red). Of course this
makes sense only, if each each page is loaded very fast -
no large images. -----G.Hoffmann
 
try this:

<TD WIDTH=&quot;20&quot; ROWSPAN=&quot;2&quot; ALIGN=&quot;center&quot; ID=&quot;test&quot; STYLE=&quot;background-color: #FF0000;&quot;>

<A href=&quot;#&quot; onClick=&quot;document.test.style.backgroundColor='#003399';&quot;>Something here</A>

Go to for specifics of the Internet Explorer document object model.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top