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.leng th; f++) {
for (e = 0; e < window.document.forms[f].e lements.le ngth; e++) {
if ( window.document.forms[f].e lements[e] .type == "select-multiple" ||
window.document.forms[f].e lements[e] .type == "select-one" ) {
elem = window.document.forms[f].e lements[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].visib ility="hid e";
window.document.forms[f].g etElementB yId("X3"). visibility ="hide";
}
else {
window.document.forms[f].e lements[e] .style.vis ibility="h idden";
}
} else {
if (isMinNS4) {
window.document.forms[f].e lements[e] .visibilit y="show";
}
else {
window.document.forms[f].e lements[e] .style.vis ibility="v isible";
}
}
}
}
}
}
}
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
var e, f, elem, elemTop, elemLeft, elemRight, elemBottom;
// Loop through all forms in document
for (f = 0; f < window.document.forms.leng
for (e = 0; e < window.document.forms[f].e
if ( window.document.forms[f].e
window.document.forms[f].e
elem = window.document.forms[f].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].visib
window.document.forms[f].g
}
else {
window.document.forms[f].e
}
} else {
if (isMinNS4) {
window.document.forms[f].e
}
else {
window.document.forms[f].e
}
}
}
}
}
}
}
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].e lements[e] ; in netscape...
Hope you can help further,
Floris.
So; I don;t know the names of the elements and will have to use elem = window.document.forms[f].e
Hope you can help further,
Floris.
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].e lements[e] ; in netscape...
Hope you can help further,
Floris.
So; I don;t know the names of the elements and will have to use elem = window.document.forms[f].e
Hope you can help further,
Floris.
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].e lements[e] ; in netscape...
Hope you can help further,
Floris.
So; I don;t know the names of the elements and will have to use elem = window.document.forms[f].e
Hope you can help further,
Floris.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
can't I?
I'll see...
I'll see...
ASKER
can't I?
I'll see...
I'll see...
This won't work:
window.document.forms[f].g
This should:
document.getElementById("X
Fritz the Blank