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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hide/Show button works in IE not Firefox

    When I click the button, the images hide/show in IE, but this doesn't work in Firefox. I've tried JSLint and JavascriptLint, but haven't figured out what the issue is. Any help would be much appreciated!! This is the code below:

    <script language="Javascript">
    <![CDATA[
    function openConsole(docId, attachmentFileName, name) {
    if (window.customOpenConsole) {
    customOpenConsole(encodeURIComponent(attachmentFileName), name);
    } else {
    headerFrame = window.parent.parent.frames["Header"];
    if (headerFrame != null && headerFrame.openDocLink != null){
    headerFrame.openDocAttachment(docId, attachmentFileName, name);
    }
    }
    }
    function STGhide()
    {
    var x=document.getElementsByName("ImageControlZone");
    for(j=0;j<x.length;j++)
    {
    var imgs = x[j].getElementsByTagName('img');
    for(i=0;i<imgs.length;i++)
    {
    imgs[i].style.display="none";
    }
    }
    var link = document.getElementById("ShowHideButton");
    //alert(link.innerHTML)
    link.innerHTML ="<img alt='' src='img/hideshow/showimage.gif' border='0' onclick='javascript:STGshow();' />";
    }
    function STGshow()
    {
    var x=document.getElementsByName("ImageControlZone");
    for(j=0;j<x.length;j++)
    {
    var imgs = x[j].getElementsByTagName('img');
    for(i=0;i<imgs.length;i++)
    {
    imgs[i].style.display="";
    }
    }
    var link = document.getElementById("ShowHideButton");
    link.innerHTML ="<img alt='' src='img/hideshow/hideimage.gif' border='0' onclick='javascript:STGhide();' />";
    }

    function openDocumentLink(externalId, languageId) {

    if (window.parent.openDocLink != null) {
    window.parent.openDocLink(externalId, languageId);
    } else {
    headerFrame = window.parent.parent.frames["Header"];
    if (headerFrame != null && headerFrame.openDocLink != null)
    {
    headerFrame.openDocLink(externalId, languageId);
    }
    else {
    setTimeout("openDocumentLink('"+externalId+"','"+languageId+"')",500);
    }
    }
    }
    ]]>
    </script>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Why do you recreate the <img> each time???

    Why not just toggle, instead?

    Can you show this live? You don't show the HTML, so it's a little hard to guess.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    I would have done something like this:
    Code:
    function STGshowhide(image)
    { 
        var doShow = image.src.indexOf("show") >= 0;
    
        var x=document.getElementsByName("ImageControlZone");
        for(j=0;j<x.length;j++)
        {
            var imgs = x[j].getElementsByTagName('img');
            for(i=0;i<imgs.length;i++)
            {
                 imgs[i].style.display = doShow ? "" : "none";
            }
        }
        image.src = "img/hideshow/" + ( doShow ? "hideimage.gif" : "showimage.gif" );
        image.alt = doShow ? "hide images" : "show images";
    }
    And then code the <img> thus:

    Code:
      <img alt="hide images" src="img/hideshow/hideimage.gif" style="border: none;" onclick="STGshowhide(this);" />
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Oh, and since the problem is in FireFox, you really need to try Firebug!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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