Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Layer visibility, help, I give up. I cant see what i am doing wrong.

    I am trying to get this to work on MS IE 5.00.xxxx
    It should take in a layer, make it invisible or visible.

    Code:
    function toggle_layer_visibility( layer_to_change ) {
    
      if ((layer_to_change != null) && (layer_to_change != "")) {
        if (document.layers) { 
          alert("Debug:  netscape");
          if (document.layers[layer_to_change].visibility == 'visible' || document.layers[layer_to_change].visibility == 'show') {
            alert("Debug: layer is currently shown. Attempting to hide:");
            document.layers[layer_to_change].visibility = 'hidden';
          } else if (document.layers[layer_to_change].visibility == 'hidden' || document.layers[layer_to_change].visibility == 'hide') {
            alert("Debug: layer is currently hidden. Attempting to show:");
            document.layers[layer_to_change].visibility = 'visible';
          } else {
          }
    
        } else if (document.all) {
          alert("Debug:  IE");
          if (document.all[layer_to_change].style) {
            alert("Debug: a style attribute exists for the " + layer_to_change);
          }
          alert("Debug: It is: " + document.all[layer_to_change].style.visibility);
          if (document.all[layer_to_change].style.visibility) {
            alert("Debug: a visibility attribute exists for the " + layer_to_change + ".  It is: " + document.all[layer_to_change].style.visibility);
          }
          if (document.all[layer_to_change].style.visibility == 'visible') {
            alert("Debug: layer is currently shown. Attempting to hide:");
            document.all[layer_to_change].style.visibility = 'hidden';
          } else if (document.all[layer_to_change].style.visibility == 'hidden') {
            alert("Debug: layer is currently hidden. Attempting to show:");
            document.all[layer_to_change].style.visibility = 'visible';
    //.style.visibility
          }
        }
       
       if (document.getElementById) {
         alert("Debug: " + document.getElementById(layer_to_change).style.visibility );
       } else {
         alert("Debug: getElementById does not exist.");
       }
    
    
      } else {
        alert('Nothing was sent to the layer_toggle_visibility function');
      }
    }

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    inseat of putting if(document.all[layer_to_change].style.visibility="visible or hidden"

    try this:

    var IEstyle=eval("document.all."+layer_to_change+".style.")

    if(IEstyle.visibility="visible"){


    ect.

    Mabye it'll work, ya never know hehe ;D;D




    Hope this helps
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Bob...

    This is where the HTMLElement.style property comes from:

    <div.........style=".........">

    It represents (in the DOM object hierarchy) the inline style attribute - from HTML. It's not a 'magic clearing house' of CSS, so unless you assign that element's CSS inline - as opposed to in a global style sheet - its .style object will remain a collection of empty strings. There are ways of 'getting computed style' (checking the entire cascade to determine the actual CSS implemented), and newer CSS platforms will have this ability built in. Till then, might try something like this:

    Code:
    function getElem(id) {
    return document.all ? document.all(id) :
    document.getElementById ? document.getElementById(id) :
    document.layers ? document.layers[id] :
    null;
    }
    
    function getVisibility(el) {
    if (el.style) {
    if (el.style.visibility && el.style.visibility != 'inherit') return el.style.visibility;
    if (el.currentStyle && el.currentStyle.visibility && el.currentStyle.visibility != 'inherit')
    return el.currentStyle.visibility;
    else while (el = el.parentElement) {
    if (el != null && el.style.visibility && el.style.visibility != 'inherit')
    return el.style.visibility;
    if (el != null && el.currentStyle && el.currentStyle.visibility && 
    el.currentStyle.visibility != 'inherit')
    return el.currentStyle.visibility;
    }
    } else if (document.layers) {
    if (el.visibility != 'inherit') return el.visibility;
    else while (el = el.parentLayer) {
    if (el != null && el.visibility != 'inherit') {
    return el.visibility;
    }
    }
    }
    return (!document.layers) ? 'visible' : 'show';
    }
    
    function toggleVis() {
    var currArg;
    for (var a=0; a<arguments.length; ++a) {
    currArg = arguments[a];
    var el = getElem(currArg);
    if (!el) return;
    if (el.style)
    el.style.visibility = (getVisibility(el) == 'visible') ? 'hidden' : 'visible';
    else if (document.layers)
    el.visibility = (getVisibility(el) == 'show') ? 'hide' : 'show';
    }
    }
    toggleVis() takes multiple arguments (element ids).

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb ... fuse in brain explodes .....

    dih,

    >Bob...
    > This is where the HTMLElement.style property comes from:
    ><div.........style=".........">

    Thx. Adios: I had just come to that conclusion that it wasnt declared until you declare it... Programming for Netscape 4.7x + got my mind into one track thinking.

    OMG... That code is great... too bad my brain cant digest it at this time. I think I will just add the following code to the page load up script. I dont want to have to explain your code to anyone who works on this after me, just yet.

    Code:
    if (document.all) {
      my_layer.style.visibility = "visible";
    }

    -S. Bob

    "And they invented javascript, and all was in chaos again"

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    %%%%
    % %
    <-- bob
    %%%%

    Quick explanation: elements inherit their CSS if it isn't applied to them directly; so, find your way up through the tree (old way), checking for set visibility, returning if found, continuing if not or if it's set to 'inherit'. If you hit the end (document element) and haven't found it, it must be the default visibility, which is, naturally, visible. The .currentStyle object is IE-only, returns the cascaded style, usually.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •