Link to home
Start Free TrialLog in
Avatar of florisb
florisb

asked on

getElementById in loop

Hi,

I'm using a function, where I loop all form elements with the purpose to hide them if a menu-item (layer) is being shown above it.

Looping the form elements works in netscape and IE, but in netscape the calls elemTop, getPageLeft, elemRight, elemBottom don't give me any result.

How can I make the script below work in netscape?

Thanks,
Floris.

function toggleSelectElements(layer, mode) {
  var e, f, elem, elemTop, elemLeft, elemRight, elemBottom;
 
  // Loop through all forms in document
  for (f = 0; f < window.document.forms.length; f++) {
     for (e = 0; e < window.document.forms[f].elements.length; e++) {
       if ( window.document.forms[f].elements[e].type == "select-multiple" ||
            window.document.forms[f].elements[e].type == "select-one" ) {
          elem = window.document.forms[f].elements[e];
          elemTop = getPageTop(elem);
          elemLeft = getPageLeft(elem);
        elemRight = elemLeft + elem.clientWidth ;
        elemBottom = elemTop + elem.clientHeight + 1;          
          // Test for overlap.
          if ( layer.left <= elemRight && layer.right >= elemLeft && layer.bottom >= elemTop ) {          
            if ( mode == 0 ) {            
                 if (isMinNS4) {
                    forms[f].elements[e].visibility="hide";
                    window.document.forms[f].getElementById("X3").visibility="hide";
                   
                    }
               else {
                      window.document.forms[f].elements[e].style.visibility="hidden";                    
                    }            
            } else {
                 if (isMinNS4) {
                     window.document.forms[f].elements[e].visibility="show";
                    }
               else {
                    window.document.forms[f].elements[e].style.visibility="visible";
                    }
            }
         }
       }
       }
  }
}
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

just use document.getElementByID() without putting the form tag in there.

This won't work:

window.document.forms[f].getElementById("X3").visibility="hide";


This should:

document.getElementById("X3").visibility="hide";

Fritz the Blank
Avatar of florisb
florisb

ASKER

Thanks, but the thing is that I use the menu on different pages with elements with different names.

So; I don;t know the names of the elements and will have to use elem = window.document.forms[f].elements[e]; in netscape...

Hope you can help further,
Floris.
Avatar of florisb

ASKER

Thanks, but the thing is that I use the menu on different pages with elements with different names.

So; I don;t know the names of the elements and will have to use elem = window.document.forms[f].elements[e]; in netscape...

Hope you can help further,
Floris.
Avatar of florisb

ASKER

Thanks, but the thing is that I use the menu on different pages with elements with different names.

So; I don;t know the names of the elements and will have to use elem = window.document.forms[f].elements[e]; in netscape...

Hope you can help further,
Floris.
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of florisb

ASKER

can't I?
I'll see...
Avatar of florisb

ASKER

can't I?
I'll see...