Solved

Change table cell color onClick

Posted on 2001-08-15
6
221 Views
Last Modified: 2008-02-01
I am trying to come up with a script that would change the color of a <TD> tag on click.. Has anyone ever done that before...thanks!
0
Comment
Question by:slimbx
6 Comments
 
LVL 4

Expert Comment

by:Gibble
ID: 6389830
<table>
<tr>
<td id="changeme" bgcolor="blue">sometext</td>
<td><span onClick="document.all('changeme').style.background = 'red'">click here</span></td>
</tr>
</table>
0
 
LVL 4

Expert Comment

by:Gibble
ID: 6389847
btw, I am not sure about NS support for this, I don't have a copy of NS nor do I ever use it so :-/
0
 

Author Comment

by:slimbx
ID: 6389965
NS support is a must for this as well. Sorry I did not specify that. I know that there are some querks, but if you can get it as close as you can, I am leniant.

slimbx
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
nzjonboy earned 45 total points
ID: 6390774
this link may give you some information on how its done. if you need more help with this then I'll post a script

http://developer.irt.org/script/1441.htm

nzjonboy
0
 
LVL 2

Expert Comment

by:damienm
ID: 6391879
The below code changes the color of a cell on mouseover and back on mouseout.

<HTML>
<HEAD>
<SCRIPT>
var highColor = 'lime'
function tdMouseOver (evt) {
   this.cell.bgColor = highColor;
}
function tdMouseOut (evt) {
   this.cell.bgColor = document.bgColor;
}
function init () {
  initTableEventHandler ('table1', 3, 3, 'mouseover', tdMouseOver);
  initTableEventHandler ('table1', 3, 3, 'mouseout', tdMouseOut);
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="init();">
<TABLE BORDER="1">
<TR>
<TD ID="table1Cell0_0" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
Kibology
</TD>
<TD ID="table1Cell0_1" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
for
</TD>
<TD ID="table1Cell0_2" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
all
</TD>
</TR>
<TR>
<TD ID="table1Cell1_0" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
Kibology
</TD>
<TD ID="table1Cell1_1" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
for
</TD>
<TD ID="table1Cell1_2" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
all
</TD>
</TR>
<TR>
<TD ID="table1Cell2_0" CLASS="cell" VALIGN="top"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
Scriptology
</TD>
<TD ID="table1Cell2_1" CLASS="cell" VALIGN="top"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
for
</TD>
<TD ID="table1Cell2_2" CLASS="cell"
    ONMOUSEOVER="this.bgColor = highColor;"
    ONMOUSEOUT="this.bgColor = document.bgColor;"
>
all.
<BR>
All for Scriptology
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
0
 

Author Comment

by:slimbx
ID: 6392899
This will do just fine. I am using a jsp page to implement something that will require clicking on table cells and changing colors. I will be hooking into some data source, to provide colors to change to. Thanks a lot for your help. I 've aded a few for your troubles. Thanks

slimbx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now