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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael

    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.
  • Woody

    #2
    Re: How can I use onclick to change a table cell background color

    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!

    Comment

    Working...