Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

getElementById in loop

Posted on 2003-03-17
7
Medium Priority
?
1,741 Views
Last Modified: 2008-02-01
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";
                    }
            }
         }
       }
       }
  }
}
0
Comment
Question by:florisb
  • 5
  • 2
7 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8152848
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
0
 
LVL 2

Author Comment

by:florisb
ID: 8152923
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.
0
 
LVL 2

Author Comment

by:florisb
ID: 8152931
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:florisb
ID: 8152961
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.
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 500 total points
ID: 8153119
Right, so can't you do something like:

for(i=0;i<document.elements.length;i++){
  alert(document.getElementById(i).name);
}


Fritz the Blank
0
 
LVL 2

Author Comment

by:florisb
ID: 8157687
can't I?
I'll see...
0
 
LVL 2

Author Comment

by:florisb
ID: 8157752
can't I?
I'll see...
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question