Hello,
I currently have a page where I have pop-up menus that work like so:
function openMenu(x) {
var items = 5
for (i=0; i<items; i++) {
if(document.layers) {
document.layers[i+1].visibility = "hide"
document.layers[x+1].visibility = "show"
document.layers[x+1].top=80
}
if(document.all) {
document.all.box[i].style.visibility = "hidden"
document.all.box[x].style.visibility = "visible"
document.all.box[x].style.top = 80
}
}
}
function closeMenu() {
var items = 5
for (i=0; i<items; i++) {
if(document.all){document.all.box[i].style.visibility = "hidden";}
if(document.layers){document.layers[i+1].visibility = "hide";}
}
}
<div id="box" style="left:200">
menu1 content
</div>
<div id="box" style="left:250">
menu1 content
</div>
<div id="box" style="left:300">
menu2 content
</div>
<div id="box" style="left:350">
menu3 content
</div>
<div id="box" style="left:400">
menu4 content
</div>
<div id="box" style="left:200">
menu5 content
</div>
An onMouseOver and onMouseOut calls the openMenu and closeMenu functions.
However, I am trying to adapt the code to DOM1/Netscape6/IE 5.5. My problem
is that I cannot figure out how to pass "box[x]" to the getElementById
method.
I have tried document.getElementById("box[x]").style.visibility="whatever"
and other variations, but cannot get it to work. I know it works if I just
put getElementById("box"), but obviously I need to be able to reference each
div.
Is there a way around this, or does each div have to have a unique id (which
will make my code more complex)?
In a simlar vein, how would you handle references to different values of,
for instance, a radio button in a form where the name/id is the same, but
the value is different? Normally I would reference each option by something
like document.formName.inputName[0], document.formName.inputName[1], etc.
Is it possible to use getElementById to reference each possible value of a
radio button?
Please forgive the long example (I hope the code comes across ok), but I am
pretty new to javascript, and am really confused. Is there some fundamental
principle here that I am totally missing?
Thanks so much in advance for any help.
Amy