Link to home
Start Free TrialLog in
Avatar of akbiro
akbiroFlag for United States of America

asked on

Show/Hide not working

I have tried to place a FAQ show/hide function on my webpage.  It works in Dreamweaver, but not when I load it on the server.  See it at http://www.garblecard.com/GC-Full.html


Here is the code:

 <section id="styles" class="clearfix">

            <h1>FAQs</h1>

            <div class="primary">

                <p class="intro">Frequently Asked Questions:</p>
                      <span id="show1" class="show"><a href="#" onClick="toggle_visibility('readthis1');">
                      <h2>Will GarbleCard mess up my credit cards?</h2></a></span><span id="readthis1" class="hide"> No. Garblecard emits no signals, emissions or transmissions.<br /></span>
               
                <span id="show2" class="show"><a href="#" onClick="toggle_visibility('readthis2');"><h2>Where should I keep the GarbleCard?</h2></a></span><span id="readthis2" class="hide"> For best results, sandwich credit and debit cards between two GarbleCards.<br /></span>

                        <span id="show3" class="show"><a href="#" onClick="toggle_visibility('readthis3');"><h2>Will GarbleCard deactivate a motel key card?</h2></a></span><span id="readthis3" class="hide"> No. Garblecard emits no signals, emissions or transmissions.  Electronic hotel keys are one of many cards that GarbleCard protects<br /></span>
               
                 
            </div>

            <aside>

                    <h2>FAQ List</h2>

                    <p>If you do not find your question, please send it along to us so we can get you the answer and add the question to our list. </p> <a href="#contact"><Strong>Ask Us.</Strong></a></p>

                    <!--<h2>Link List</h2>

                    <ul class="link-list">
                        <li><a href="#">Maecenas eu neque</a></li>
                        <li><a href="#">Dolor eget libero</a></li>
                        <li><a href="#">Lorem Ipsum</a></li>
                        <li><a href="#">Gravida fermentum urna</a></li>
                    </ul>

                    <h2>Testimonials</h2>

                    <div class="testimonials">
                        <blockquote>
                            <p>Donec sed odio dui. Nulla vitae elit libero, a pharetra augue.
                            Nullam id dolor id nibh ultricies vehicula ut id elit. </p>

                            <cite>&mdash; John Doe, XYZ Company</cite>
                        </blockquote>
                        <blockquote>
                            <p>Aenean lacinia bibendum nulla sed consectetur. Cras mattis
                            consectetur purus sit amet fermentum.</p>

                            <cite>&mdash; Jane Roe, ABC Corp</cite>
                        </blockquote>
                    </div>-->

            </aside>

            <a class="back-to-top" href="#main">Back to Top</a>

      </section>
Avatar of John Easton
John Easton
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not sure if this is the cause, but your code read 'onClick', however it should be 'onclikc' i.e. without the capital C.  While some browsers will allow this other will not and it could be the cause.
Avatar of akbiro

ASKER

Thank you.  I made the change and it still does not work.  Any other ideas?
Reading a bit further I have noticed a couple of issues in the HEAD of the page code.  Firstly your toggle_visibility function isn't contained in <script> tags and the IF statements should have {} around the code as follows:
 function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.className == 'show') 
       	{
          e.className = 'hide';
        }
       else
       	{
          e.className = 'show';
        }
    } 

Open in new window


In my test page it works on the first line only, so I am still looking...
Avatar of akbiro

ASKER

Wow...well that made the Show/Hide work in Dreamweaver, but not when I load it on the server.
Ok, I think I have made some progress.  Firstly, there are two functions with the same name 'toggle_vidibility'.  Firstly, delete the one in the HEAD section.  This will undo the change I suggested above.

Now you will only have one function with this name about 10 lines below your <body> tag.  Replace that with the following:
<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(document.defaultView.getComputedStyle(document.getElementById(id), '').getPropertyValue("display")!= "none")
       {
          e.style.display = "none";
       }
       else
       {
          e.style.display = "block";
       }
       return false;
    }
//-->
</script>

Open in new window


This works for me on my test page, so hopefully it will work for you too.
Oh, one last change (I hope).  From the above remove the "return false" line, it isn't doing anything.

If you have the same issue I do - that when clicking the link the page jumps back to the top - then change each of your functions calls from:
<a href="#" onclick="toggle_visibility('readthis1');">

Open in new window

to
<a href="#" onclick="toggle_visibility('readthis1');return false;">

Open in new window


I.e. just add the "return false;" text after the call to the function.
Avatar of akbiro

ASKER

Almost...when I load it on the server, clear my cache and run the page, all the questions come up with the answers displayed.  If I click on the questions I can show and hide them.  I want them hidden until the question is clicked.  Thanks
You can either add the below into your current page:
<style>
.hide
{
	display:none;
}
</style>

Open in new window

Or update your stylesheet with the same.
Avatar of akbiro

ASKER

Thanks for your patience.  I changed style.css and it still is not working...thanks
Avatar of akbiro

ASKER

It works PERFECTLY in Dreamweaver.
That threw me for a moment.  Your CSS has a section which starts '@media screen', if you move the properties you have added above this line it should work fine.
Avatar of akbiro

ASKER

How cool are you.  PERFECT.  I am working on another section over the weekend...I want to replace the Image functions in Featured Works section to use video in the thumbnails with three funtions:

1)  Show a thumb nail image
2)  Roll over it and see a thumb nail video presentation
3)  Click on it and get the larger sized video presentation.

So far, I have gotten no where on this.  If you see me on EE, please jump in and help.  

THANKS again for this assistance.
Avatar of akbiro

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for akbiro's comment #a39210579

for the following reason:

Excellent and with patience.  Appreciate the help...could not have found it myself.
ASKER CERTIFIED SOLUTION
Avatar of John Easton
John Easton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of akbiro

ASKER

Oops,...thank you for doing a great job.  Thanks for your patience with me.  I would never have solved this on my own!!!