Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

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>
0
akbiro
Asked:
akbiro
  • 8
  • 7
1 Solution
 
John EastonDirectorCommented:
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.
0
 
akbiroAuthor Commented:
Thank you.  I made the change and it still does not work.  Any other ideas?
0
 
John EastonDirectorCommented:
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...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
akbiroAuthor Commented:
Wow...well that made the Show/Hide work in Dreamweaver, but not when I load it on the server.
0
 
John EastonDirectorCommented:
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.
0
 
John EastonDirectorCommented:
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.
0
 
akbiroAuthor Commented:
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
0
 
John EastonDirectorCommented:
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.
0
 
akbiroAuthor Commented:
Thanks for your patience.  I changed style.css and it still is not working...thanks
0
 
akbiroAuthor Commented:
It works PERFECTLY in Dreamweaver.
0
 
John EastonDirectorCommented:
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.
0
 
akbiroAuthor Commented:
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.
0
 
akbiroAuthor Commented:
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.
0
 
John EastonDirectorCommented:
I think the user has selected the wrong comment to awards points to.  They have selected their own comment, although the text suggest they were happy with the responce!

To akbiro:  Glad I could help!
0
 
akbiroAuthor Commented:
Oops,...thank you for doing a great job.  Thanks for your patience with me.  I would never have solved this on my own!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now