473,722 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I use onclick to change a table cell background color

How can I use onclick to change a table cell background color. I know
I can use this.className= ?

to change the classname. But then I would have to put the code into
every single table cell. I read once about using a collection method.

Lets say a table has 100 TD Cells with a white background. I want to
click on just 1 and then have it change to a Yellow background. Then
when I click on a different Cell have the old one change back to white
and the new Cell change to Yellow. etc.
Jul 23 '05 #1
1 3771
function BgnDay_onclick( ) {
var IdString = ""
var TempDay = 0
var GoodPick = true

if (DateSet == false) {
IdString = window.event.sr cElement.id;
if (IdString.lengt h < 4) {
IdString = window.event.sr cElement.parent Element.id;
if (IdString.lengt h < 4)
IdString = window.event.sr cElement.parent Element.parentE lement.id; }
if (document.all(I dString).innerT ext !== "") {
TempDay = Math.abs(CellTo DayNumber(IdStr ing));
if (document.all(I dString).style. backgroundColor !== "red") {
if (StartCell.leng th > 0) {
BackColor(Start Cell);
StartDay = TempDay; }
RedItOut(IdStri ng);
StartDay = Math.abs(CellTo DayNumber(IdStr ing));
StartCell = IdString;}
else
{ BackColor(IdStr ing);
StartCell = "";
StartDay = 0 }}}
DisplayDate();

butchered from some code i wrote for a project

Woody
any sugestion or comment made by me should be examined first for
validity and appropriateness before assuming i have any idea at all
what the heck i am talking about. I am not responsible for anything you
may see with my name attached to it, i think.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6643
by: A.S. | last post by:
Hi, I have the following simple code: <TABLE><TR> <TD BGCOLOR="#FFFFFF" ONCLICK="myform.color.value = this.bgcolor">hello</TD> </TR></TABLE> <FORM ACTION="hello.cgi" NAME="myform" ID="myform">
1
2570
by: Tony Farrell | last post by:
Hi everyone - I am trying to accomplish a task that i thought would be easy - and at this point - i'm starting to wonder... I have a table setup, one column, ten rows All the cells start off with a white background, as the mouse passes over the cell, the background color changes to a nice light blue. I have that working ok -
3
4774
by: michael | last post by:
I'm changing colors of table cells like this: <style type="text/css"> ..over {background-color: #bedddc} ..out {background-color: #99cccc} </style> <td onmouseover="this.className='over'" onmouseout="this.className='out'">
3
4764
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
0
3170
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where there are tabs at the top with "submenu" buttons showing below the selected tab. The data that defines the tabs and submenus is stored in an XML file and I'm using nested repeaters to build them dynamically. I've got it working pretty well, except...
4
10775
by: HB | last post by:
So I have a table in ASP.NET <table runat="server" id="tblMyTable"> <tr> <td id="cellMyCell">word</td> </tr> </table> How do I reference the cell "cellMyCell" from the Vb.NET 1.1 code-behind to change the background color of the cell?
9
1974
by: shroud77 | last post by:
The general gist here is that I have a cell in a table that I would like to have change background color based on whether or not the checkbox within it is selected or not. The checkbox can be selected by clicking on either the cell or the checkbox... I am working in PHP, so the call to the function that would do this includes $block_name to identify the checkbox. onClick="box_event('$block_name')" (this is in both the <td> and checkbox...
3
2714
by: nma | last post by:
Hi How do I make the cell change color to 'black' after I click on it. The cell will remain black color until I click another cell which will also change to black. I can do the mouseover and mouseout correctly only to make it change color to black once I click on it. Could someone help? Thansk nma <td width="<?php echo ($cellwidth); ?>" height="17" bgcolor="#00ff00" onMouseOver="this.style.background ='red'"
2
3809
by: Jim | last post by:
How can I use JavaScript to change a background image in a table cell? Here's the code for the cell <td width="338" valign="top" background="../images/ LEC_Q1.jpg"><div align="right"></div></td> You can see that the background is set to the image LEC_Q1.jpg. I want to change the image LEC_Q1.jpg to LEC_Q1_faded.jpg after a user clicks a button and the only way I can figure out to do it is by using
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.