Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2003
    Location
    Somerset
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using a variable as a object name in a statement

    I'm trying to change the class of a table cell using JavaScript with the onClick event of another cell.

    If I use the cell ID (tab1) in the statment:

    tab1.className="tabmenuoff";

    it works.

    But if I assign the cell ID value to a variable and use that as the object ID in the statement:

    var tabname="tab1";
    tabname.className="tabmenuoff";

    it doesn't. But I get no errors

    I need to use a variable because I need to change a number of cells and use the 'for' loop to accomplish this using the numeric value on the end of the object name.

    I'm sure the answer is very simple but I'm new to this - can anyone help!!!!

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The statement:

    tabname.className="tabmenuoff";

    Still has the script looking for a cell named "tabname". Some one will need to jump in here but you would do something like the following:

    cells[tabname].className="tabmenuoff";


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •