Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-27-2011, 08:17 PM   PM User | #1
Squishy435
New Coder

 
Join Date: May 2010
Location: Saint Louis, MO
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Squishy435 is an unknown quantity at this point
Question FAQ Drop-Down A when Q is clicked?

Hi everyone - I was wondering how it would be possible for me to create a FAQ with drop-down answers when the question is clicked?

For example: https://www.facebook.com/help/?page=1145

Facebook has something like that available.

Any ideas?
Squishy435 is offline   Reply With Quote
Old 08-27-2011, 10:21 PM   PM User | #2
Squishy435
New Coder

 
Join Date: May 2010
Location: Saint Louis, MO
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Squishy435 is an unknown quantity at this point
Quote:
Originally Posted by Squishy435 View Post
Hi everyone - I was wondering how it would be possible for me to create a FAQ with drop-down answers when the question is clicked?

For example: https://www.facebook.com/help/?page=1145

Facebook has something like that available.

Any ideas?
Here is another example that I managed to find: http://www.thereconnection.com/faq
Squishy435 is offline   Reply With Quote
Old 08-27-2011, 11:05 PM   PM User | #3
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 814
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
here's something to get you started ...

Code:
<HTML>
<BODY>
<DIV STYLE="cursor:hand;cursor:pointer"
onclick="document.getElementById('hidden').style.display='inline'"
>whassup?
</DIV>
<div id="hidden" style="display:none">nadda<br></div>
hiyas
</BODY>
</HTML>

Last edited by DaveyErwin; 08-27-2011 at 11:26 PM..
DaveyErwin is offline   Reply With Quote
Users who have thanked DaveyErwin for this post:
Squishy435 (08-28-2011)
Old 08-28-2011, 12:56 AM   PM User | #4
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,799
Thanks: 30
Thanked 463 Times in 457 Posts
jmrker will become famous soon enough
Lightbulb

Slight modification from last post to include a bit more JS and some CSS.

Only advantage is that click on question box shows/hides the answer
and the box makes it easier to know where to put cursor for mouse click.

Code:
<!DOCTYPE HTML>
<html>
<head>
<title> FAQ Display </title>
<style type="text/css">
 .FAQ { cursor:hand; cursor:pointer;
        border:1px solid red; width:50%; }
 .FAA { display:none; }
</style>
<script type="text/javascript">
function toggle(Info) {
  var CState = document.getElementById(Info);
  CState.style.display = (CState.style.display != 'block')
                       ? 'block' : 'none';
}
</script>
</head>
<body>
<h2>FAQ section</h2>

<DIV class="FAQ" onclick="toggle('faq1')">
 whassup?
 <div id="faq1" class="FAA">nadda</div>
</DIV>

<DIV class="FAQ" onclick="toggle('faq2')">
 whassup now?
 <div id="faq2" class="FAA">still nadda</div>
</DIV>

<DIV class="FAQ" onclick="toggle('faq3')">
 How about now?
 <div id="faq3" class="FAA">How many times must I say <b>nothing</b>?</div>
</DIV>

</body>
</html>
jmrker is offline   Reply With Quote
Users who have thanked jmrker for this post:
Squishy435 (08-28-2011)
Old 08-28-2011, 01:35 AM   PM User | #5
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
Quote:
Originally Posted by Squishy435 View Post

For example: https://www.facebook.com/help/?page=1145

Facebook has something like that available.
This has the up/down arrows functionality like on Fb.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <style type="text/css">
            ul {
                list-style-type: none
            }
            .more_content {
                margin: 10px 0px 0px 50px;
                padding: 5px 5px 5px 5px;
                width: 200px;
                height: 100px;
                border: 1px solid black;
                overflow: auto;
                display: none
            }
            span {
                padding: 0px 0px 0px 50px;
            }
            span:hover {
                cursor: pointer;
            }
        </style>
        <script type="text/javascript">
            function showHideMore(obj) {
                var contObj = obj.parentNode.getElementsByTagName('div')[0];
                var status = (contObj.style.display == 'block')? 'none' : 'block'
                contObj.style.display = status;
                obj.innerHTML = (status == 'block')? 'Show less' : 'Show more';
                obj.curPic = (obj.curPic == 0)? 1 : 0;
                obj.style.backgroundImage = 'url("'+plusMinusPics[obj.curPic]+'")';
            }
            window.onload=function(){
                plusMinusPics = ['plus.png','minus.png'];
                oMoreLessSpans = document.getElementById('list1').getElementsByTagName('span');
                for(i=0; i < oMoreLessSpans.length; i++){
                    oMoreLessSpans[i].curPic = 0;
                    oMoreLessSpans[i].style.background = 'url("'+plusMinusPics[oMoreLessSpans[i].curPic]+'") no-repeat 0 50%';
                    oMoreLessSpans[i].onclick=function(){showHideMore(this);}
                }
            }
        </script>
    </head>
    <body>
        <div>
            <ul id="list1">
                <li>
                    <div>
                        <span>Show more</span>
                        <div class="more_content">More 1 content</div>
                    </div>
                </li>
                <li>
                    <div>
                        <span>Show more</span>
                        <div class="more_content">More 2 content</div>
                    </div>
                </li>
                <li>
                    <div>
                        <span>Show more</span>
                        <div class="more_content">More 3 content</div>
                    </div>
                </li>
            </ul>
        </div>
    </body>
</html>
webdev1958 is offline   Reply With Quote
Users who have thanked webdev1958 for this post:
Squishy435 (08-28-2011)
Old 08-28-2011, 01:52 AM   PM User | #6
Squishy435
New Coder

 
Join Date: May 2010
Location: Saint Louis, MO
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Squishy435 is an unknown quantity at this point
Quote:
Originally Posted by jmrker View Post
Slight modification from last post to include a bit more JS and some CSS.

Only advantage is that click on question box shows/hides the answer
and the box makes it easier to know where to put cursor for mouse click.

Code:
<!DOCTYPE HTML>
<html>
<head>
<title> FAQ Display </title>
<style type="text/css">
 .FAQ { cursor:hand; cursor:pointer;
        border:1px solid red; width:50%; }
 .FAA { display:none; }
</style>
<script type="text/javascript">
function toggle(Info) {
  var CState = document.getElementById(Info);
  CState.style.display = (CState.style.display != 'block')
                       ? 'block' : 'none';
}
</script>
</head>
<body>
<h2>FAQ section</h2>

<DIV class="FAQ" onclick="toggle('faq1')">
 whassup?
 <div id="faq1" class="FAA">nadda</div>
</DIV>

<DIV class="FAQ" onclick="toggle('faq2')">
 whassup now?
 <div id="faq2" class="FAA">still nadda</div>
</DIV>

<DIV class="FAQ" onclick="toggle('faq3')">
 How about now?
 <div id="faq3" class="FAA">How many times must I say <b>nothing</b>?</div>
</DIV>

</body>
</html>
This is probably more like that I'm looking for. Thank you very much. Just a little modifications that I have to make, and then I should be good to go.
Squishy435 is offline   Reply With Quote
Old 12-03-2012, 04:37 PM   PM User | #7
Markymark74
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Markymark74 is an unknown quantity at this point
Quote:
Originally Posted by jmrker View Post
Slight modification from last post to include a bit more JS and some CSS.

Only advantage is that click on question box shows/hides the answer
and the box makes it easier to know where to put cursor for mouse click.

Code:
<!DOCTYPE HTML>
<html>
<head>
<title> FAQ Display </title>
<style type="text/css">
 .FAQ { cursor:hand; cursor:pointer;
        border:1px solid red; width:50%; }
 .FAA { display:none; }
</style>
<script type="text/javascript">
function toggle(Info) {
  var CState = document.getElementById(Info);
  CState.style.display = (CState.style.display != 'block')
                       ? 'block' : 'none';
}
</script>
</head>
<body>
<h2>FAQ section</h2>

<DIV class="FAQ" onclick="toggle('faq1')">
 whassup?
 <div id="faq1" class="FAA">nadda</div>
</DIV>

<DIV class="FAQ" onclick="toggle('faq2')">
 whassup now?
 <div id="faq2" class="FAA">still nadda</div>
</DIV>

<DIV class="FAQ" onclick="toggle('faq3')">
 How about now?
 <div id="faq3" class="FAA">How many times must I say <b>nothing</b>?</div>
</DIV>

</body>
</html>
How do i add the plus and minus images to this?
Markymark74 is offline   Reply With Quote
Old 12-04-2012, 01:38 AM   PM User | #8
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,799
Thanks: 30
Thanked 463 Times in 457 Posts
jmrker will become famous soon enough
Lightbulb

You should substitute you own images (and path)
Code:
<!DOCTYPE HTML>
<html>
<head>
<title> FAQ Display </title>
<style type="text/css">
 .FAQ { cursor:hand; cursor:pointer;
        border:1px solid red; width:25%; }
 .FAA { display:none; }
</style>
<script type="text/javascript">
function toggle(Info,pic) {
  var CState = document.getElementById(Info);
  CState.style.display = (CState.style.display != 'block') ? 'block' : 'none';
// alert(CState.style.display+'\n'+pic.src);
  if (CState.style.display == 'none') {
    pic.src = "http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg";
  } else {
    pic.src = "http://i352.photobucket.com/albums/r360/hypnic_imp/tinyicons/splashy/remove_minus_sign.png";
  }
}
</script>
</head>
<body>
<h2>FAQ section</h2>

<DIV class="FAQ">
 <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq1',this)"> 
 whassup?
 <div id="faq1" class="FAA">nadda</div>
</DIV>

<DIV class="FAQ">
 <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq2',this)"> 
 whassup now?
 <div id="faq2" class="FAA">still nadda</div>
</DIV>

<DIV class="FAQ">
 <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq3',this)"> 
 How about now?
 <div id="faq3" class="FAA">How many times must I say <b>nothing</b>?</div>
</DIV>

</body>
</html>
jmrker is offline   Reply With Quote
Old 12-04-2012, 01:54 AM   PM User | #9
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,799
Thanks: 30
Thanked 463 Times in 457 Posts
jmrker will become famous soon enough
Lightbulb

Another version with <li> tags instead of <div>
Modified CSS for fun.
Code:
<!DOCTYPE HTML>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html>
<head>
<title> FAQ Display </title>
<style type="text/css">
 .FAQ { cursor:hand; cursor:pointer; }
 .FAA { display:none; }
 #FAQlist li { list-style-type: none; }
 #FAQlist ul { margin-left:0px; }
</style>

</head>
<body>
<h2>FAQ section</h2>

<ul id="FAQlist" style="width:33%">
 <li class="FAQ">
  <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq1',this)"> 
  Whassup?
  <div id="faq1" class="FAA">Nadda</div>
  <hr>
 </li>

 <li class="FAQ">
  <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq2',this)"> 
  Whassup now?
  <div id="faq2" class="FAA">Still nadda</div>
  <hr>
 </li>

 <li class="FAQ">
  <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq3',this)"> 
  How about now?
  <div id="faq3" class="FAA">How many times must I say <b>nothing</b>?</div>
  <hr>
 </li>

 <li class="FAQ">
  <img src="http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg" onclick="toggle('faq4',this)"> 
  ?Que pasa?
  <div id="faq4" class="FAA">Nothing in a different language.</div>
  <hr>
 </li>
</ul>

<script type="text/javascript">
function toggle(Info,pic) {
  var CState = document.getElementById(Info);
  CState.style.display = (CState.style.display != 'block') ? 'block' : 'none';
  if (CState.style.display == 'none') {
    pic.src = "http://i40.photobucket.com/albums/e244/jookah_1/plus.jpg";
  } else {
    pic.src = "http://i352.photobucket.com/albums/r360/hypnic_imp/tinyicons/splashy/remove_minus_sign.png";
  }
}
</script>
</body>
</html>
jmrker is offline   Reply With Quote
Reply

Bookmarks

Tags
drop-down question answer

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:21 AM.


Advertisement
Log in to turn off these ads.