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

Discussion in 'Javascript' started by Michael, May 14, 2004.

  1. Michael

    Michael Guest

    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.
    Michael, May 14, 2004
    #1
    1. Advertising

  2. Michael

    Woody Guest

    function BgnDay_onclick() {
    var IdString = ""
    var TempDay = 0
    var GoodPick = true

    if (DateSet == false) {
    IdString = window.event.srcElement.id;
    if (IdString.length < 4) {
    IdString = window.event.srcElement.parentElement.id;
    if (IdString.length < 4)
    IdString = window.event.srcElement.parentElement.parentElement.id; }
    if (document.all(IdString).innerText !== "") {
    TempDay = Math.abs(CellToDayNumber(IdString));
    if (document.all(IdString).style.backgroundColor !== "red") {
    if (StartCell.length > 0) {
    BackColor(StartCell);
    StartDay = TempDay; }
    RedItOut(IdString);
    StartDay = Math.abs(CellToDayNumber(IdString));
    StartCell = IdString;}
    else
    { BackColor(IdString);
    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!
    Woody, May 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thanks
    Replies:
    1
    Views:
    554
    Thanks
    Feb 8, 2004
  2. brucie
    Replies:
    2
    Views:
    488
    brucie
    Jan 1, 2004
  3. HB
    Replies:
    4
    Views:
    20,770
    Mark Rae
    May 7, 2006
  4. Arthur Shapiro
    Replies:
    29
    Views:
    313
    Arthur Shapiro
    Jan 2, 2005
  5. apparker
    Replies:
    10
    Views:
    358
    apparker
    Apr 3, 2007
Loading...

Share This Page