Solved

changing visiblity in NS6 and ie5

Posted on 2001-06-18
8
310 Views
Last Modified: 2012-06-27
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("divName");
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
0
Comment
Question by:alxr66
  • 3
  • 3
  • 2
8 Comments
 
LVL 1

Expert Comment

by:nivel
ID: 6203591
SetVisible("mydiv", true);

function SetVisible(divname, showIt) {
  document.all(divname).style.visibility
  = (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.
0
 
LVL 1

Expert Comment

by:nivel
ID: 6203600
Ooops, I mixed things up a bit there.

style.display can be "block" or "hidden".
style.visibility can be "visible" or "hidden"

Sorry.
0
 
LVL 2

Expert Comment

by:lectos
ID: 6203739
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.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:alxr66
ID: 6204531
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.
0
 

Author Comment

by:alxr66
ID: 6204534
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
0
 
LVL 2

Expert Comment

by:lectos
ID: 6204595
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.visibility = "hidden";}
else {id.style.visibility = "visible";}
}


0
 
LVL 2

Accepted Solution

by:
lectos earned 50 total points
ID: 6204629
Ooops, I meant

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.visibility = "hidden";}
else {id.style.visibility = "visible";}
}}

0
 

Author Comment

by:alxr66
ID: 6207626
Thanx lectos, problem solved!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Scroll To Top 5 38
function parameter and using that as array 15 22
multiple selects 23 48
Html input text color the frame line 2 20
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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…

839 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