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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    show_hide works in ie7, opera9, not ff2

    The following code, designed to give browsers the ability to show or hide answers to faqs by clicking the question, works perfectly in ie7 and opera 9. It doesn't, however, work at all in FireFox 2. Does anyone have any suggestions for how to make it work in FF?

    Function definition:
    Code:
    <script>
    <!--
    //IGNORE THIS PIECE OF CODE
    function show_hide(element){
    	if (eval(element+'.style.display=="none"')){
    		eval(element+'.style.display=""')
    	}
    	else
    	{
    		eval(element+'.style.display="none"')
    	}
    }
    //-->
    </script>
    Later on, the actual section to be manipulated:
    Code:
          <a href="javascript:show_hide('whatisaim')">Click here to show or hide the answer to this faq.</a><br>
          <div id="whatisaim">
                  This is where the actual text would go, which would be either hidden or shown, toggling each time the href is clicked.
                </div>
    At the end of the page, before the closing html tag:
    Code:
    <script>whatisaim.style.display='none';</script>
    Of course, these last two parts are repeated for each question.
    You can find the actual page here: http://www.aiminternational.org/about/faq.htm

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tested this out. You just need a slight change in your show_hide function. Try this one:

    Code:
    function show_hide(element){
        element=document.getElementById(element);
        
        if (element.style.display == "none"){
            element.style.display = "";
        }
        else
        {
            element.style.display = "none";
        }
    }
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Yay!

    Thanks! That worked perfectly!
    I also had to change:
    Code:
    <script>whatisaim.style.display='none';</script>
    to:
    Code:
    <script>document.getElementById('whatisaim').style.display='none';</script>
    Now it works in all three (so long as they have JS enabled).

    Thank you SO much!


  •  

    Posting Permissions

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