?
Solved

getElementById in loop

Posted on 2003-03-17
7
Medium Priority
?
1,731 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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

777 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