alxr66
asked on
changing visiblity in NS6 and ie5
im trying to change the visibility of divs in NS6 and ie5. I havent yet tested it in netscape but internet explorer keeps giving me an error when it reaches the var id=getElementById(menu) part. menu is set by: onMouseOver=toggle("divNam e");
here's the script:
function toggle(menu)
{
if(document.layers)
{ visible = "show";
hidden = "hide";
if(menu.visibility == "show")
{
menu.visibility = hidden;}
else
{menu.visibility = visible;}
}
if (document.getElementById)
{var id=document.getElementById (eval(menu ));
alert(id);
if (id.style.visibility == "visible")
{id.style.visibility = "hidden";}
else
{id.style.visibility = "visible";}
}
thanks
here's the script:
function toggle(menu)
{
if(document.layers)
{ visible = "show";
hidden = "hide";
if(menu.visibility == "show")
{
menu.visibility = hidden;}
else
{menu.visibility = visible;}
}
if (document.getElementById)
{var id=document.getElementById
alert(id);
if (id.style.visibility == "visible")
{id.style.visibility = "hidden";}
else
{id.style.visibility = "visible";}
}
thanks
Ooops, I mixed things up a bit there.
style.display can be "block" or "hidden".
style.visibility can be "visible" or "hidden"
Sorry.
style.display can be "block" or "hidden".
style.visibility can be "visible" or "hidden"
Sorry.
Instead of:
var id=document.getElementById (eval(menu ));
Try:
var id=document.getElementById (menu);
You don't need the eval() in the way you are using the functions. It's probably what is causing the error.
var id=document.getElementById
Try:
var id=document.getElementById
You don't need the eval() in the way you are using the functions. It's probably what is causing the error.
ASKER
no lectos, that doesn't help, in the alert(id); id is alerted as "null". and then ie says "object requiered" so its something else.
ASKER
Nivel:
the reason your code doesn't work in NS6 is because netscape doesn't support document.all you have to use getElementById which is also supported by ie5
the reason your code doesn't work in NS6 is because netscape doesn't support document.all you have to use getElementById which is also supported by ie5
I tried the above script out once I got home from work. I fixed the {} problem from above and it works fine as far as I can tell.
function toggle(menu){
if(document.layers) {
visible = "show";
hidden = "hide";
if(menu.visibility == "show"){ menu.visibility = hidden;}
else {menu.visibility = visible;}
}
if (document.getElementById) {var id=document.getElementById (menu); }
alert(id);
if (id.style.visibility == "visible"){id.style.visibi lity = "hidden";}
else {id.style.visibility = "visible";}
}
function toggle(menu){
if(document.layers) {
visible = "show";
hidden = "hide";
if(menu.visibility == "show"){ menu.visibility = hidden;}
else {menu.visibility = visible;}
}
if (document.getElementById) {var id=document.getElementById
alert(id);
if (id.style.visibility == "visible"){id.style.visibi
else {id.style.visibility = "visible";}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx lectos, problem solved!
function SetVisible(divname, showIt) {
document.all(divname).styl
= (showIt?"block":"none");
}
This works only in ie5 though.
If you find out how to do it in ns6 then I'd like to know.