SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Modifying table cell classes in another frame...

    I've been wrestling with this problem since yesterday, and I'm no closer to solving it than I was then.

    Here's the scenario:
    I have a page with two frames. A frame named 'menuFrame' at the top, and a frame named 'mainFrame' below.

    'menuFrame' contains a table, named 'menu1'. It has one row with 6 cells in the row. Each cell has a different id.

    The idea is that each cell contains a menu option which can either be 'on' or 'off' depending on its class.

    I've been trying to write a JavaScript function called 'MenuSwitchOn(SwitchMenu)' which will do two things:
    1. It will set the class of all the cells to 'off'
    2. It will set the class of the cell specified by 'SwitchMenu' to 'on'.


    Here's the function I came up with (it says PHP but it's really JavaScript):
    PHP Code:
    function MenuSwitchOn(switchMenu) {
        var 
    menulength window.frames['menuFrame'].menuRow.cells.length;
        
        for (var 
    i=0i<menulengthi++) {
            
    window.frames['menuFrame'].menu1.rows[0].cells[i].class = 'off';
            if (
    switchMenu && window.frames['menuFrame'].menu1.rows[0].cells[i].id==switchMenu) {
                var 
    switchOn i;
            }
        }
        
        if(
    switchMenu) { 
            
    window.frames['menuFrame'].menu1.rows[0].cells[switchOn].class = 'on';
        }

    The problem is I keep getting an error "missing name after . operator" on the following line:
    Code:
    window.frames['menuFrame'].menu1.rows[0].cells[i].class = 'off';
    Does anyone have any advice for me? I'm pretty new at JavaScript...

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Code:
    <table><tr><td class="on" id="a">ddd
    </td></tr></table>
    <script>
    alert(document.getElementById('a').class)
    alert(document.getElementById('a').className)
    </script>
    As you can see from the above, you access the class with 'className'


    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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