473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Showing hidden answer when question clicked?

I've Googled, but can't find what I need, perhaps I asking the wrong
question!

I want a "FAQ" page on a web site, I hate those pages that scroll you to
the answer so and I figured that a good way to do it would be to have
hidden content under each question, something like this [the text in the
brackets should appear when the question is clicked]:

What is the first letter of the alphabet?
[The first letter of the alphabet is "A"]

What is 5 + 5?
[5 + 5 is 10]

I'd like to have each answer loaded, so it appears straight away, and
ideally in a form that I can easily edit.

Any suggestions?
--
Nigel M

"Time may be a great healer,
but he's a lousy beautician"
Jul 23 '05 #1
4 3029
Nigel Molesworth wrote:
I've Googled, but can't find what I need, perhaps I asking the wrong
question!

I want a "FAQ" page on a web site, I hate those pages that scroll you to
the answer so and I figured that a good way to do it would be to have
hidden content under each question, something like this [the text in the
brackets should appear when the question is clicked]:

What is the first letter of the alphabet?
[The first letter of the alphabet is "A"]

What is 5 + 5?
[5 + 5 is 10]

I'd like to have each answer loaded, so it appears straight away, and
ideally in a form that I can easily edit.

Any suggestions?


The following shows/hides answers when the question is clicked. It
should be pretty easy to maintain - the answers are only hidden and the
hide/show onclick function is only added if scripting support is
available. Put the styles and script in external files and you have a
very simple page where non-script visitors are not too badly treated.

Each question id needs to have a matching answer id.

The script depends on getElementById and getElementsByTa gName, you
should read the group FAQ regarding support for browsers that are
dependent on document.all (e.g. IE 4) if you wish to support them.

<URL:http://www.jibbering.c om/faq/#FAQ4_15>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Q & A </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">

<style type="text/css">
..Q, .A {
font-family: verdana, sans-serif;
width: 20em;
}
..Q {
cursor: pointer;
font-weight: bold;
padding: 15px 5px 5px 5px;
color: #333366;
background-color: #CCFFFF;
}
..A {
padding: 5px 5px 15px 5px;
color: #CC0033;
background-color: #FFFF99;
border: 1px solid #6600FF;
}
</style>
<script type="text/javascript">
function initQnA() {
if ( !document.getEl ementById || !document.getEl ementsByTagName ) {
return null;
}
var divs = document.getEle mentsByTagName( 'div')
var x, i = divs.length;
if ( divs[0].style ) {
while ( i-- ) {
x = divs[i];
if ( x.className ) {
if ( 'Q' == x.className ) {
x.onclick = function() {showHideA(this )};
x.title = 'Click to show/hide answer';
} else if ( 'A' == x.className ) {
x.style.display = 'none';
}
}
}
}
}

function showHideA(dQ){
var dAid = 'A-' + dQ.id.split('-')[1];
var dA = document.getEle mentById(dAid);
dA.style.displa y = ( 'none' == dA.style.displa y )? '' : 'none';
}

window.onload = initQnA;

</script>
</head><body>

<div id="Q-1" class="Q">What is the first letter of the alphabet?</div>
<div id="A-1" class="A">[The first letter of the alphabet is "A"]</div>

<div id="Q-2" class="Q">What is 5 + 5?</div>
<div id="A-2" class="A">[5 + 5 is 10]</div>

</body>
</html>

--
Rob
Jul 23 '05 #2
In comp.lang.javas cript, RobG wrote:
The following shows/hides answers when the question is clicked.


Absolutely fantastic, exactly what I needed. Thank you so much.
--
Nigel M

"Time may be a great healer,
but he's a lousy beautician"
Jul 23 '05 #3
JRS: In article <8p************ *************** *****@4ax.com>, dated
Mon, 13 Jun 2005 23:39:49, seen in news:comp.lang. javascript, Nigel
Molesworth <re***@thegroup .com> posted :

I want a "FAQ" page on a web site, I hate those pages that scroll you to
the answer so and I figured that a good way to do it would be to have
hidden content under each question, something like this [the text in the
brackets should appear when the question is clicked]:


You might prefer that, but will all your possible readers prefer it?

I suggest adding a "Reveal All" button at the top, which on being
clicked changes its label and function to Hide All.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
ASM
RobG wrote:
Nigel Molesworth wrote:
I've Googled, but can't find what I need, perhaps I asking the wrong
question!

I want a "FAQ" page on a web site, I hate those pages that scroll you to
the answer so and I figured that a good way to do it would be to have
hidden content under each question, something like this [the text in the
brackets should appear when the question is clicked]:

What is the first letter of the alphabet?
[The first letter of the alphabet is "A"]

What is 5 + 5?
[5 + 5 is 10]

I'd like to have each answer loaded, so it appears straight away, and
ideally in a form that I can easily edit.

Any suggestions?


The following shows/hides answers when the question is clicked.

and following would work on my NC4 :-)

<form>
<p>What is 5 + 5?
<input type=button onclick="R_001. value=' 5 + 5 is 10';" value="?">
<input type=text name="R_001">
<p>What is 5 x 5?
<input type=button onclick="R_002. value=' 5 x 5 is 25';" value="?">
<input type=text name="R_002">
</form>
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
6285
by: Nigel Molesworth | last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong question! I want a "FAQ" page on a web site, I hate those pages that scroll you to the answer so and I figured that a good way to do it would be to have hidden content under each question, something like this : What is the first letter of the alphabet?
2
2216
by: c.anandkumar | last post by:
Hi All - I have some problems getting a small piece of javascript working correctly for Firefox. Here is what I am trying to do - 1. I have a form (like a search form) 2. I have many groups of searchable fields in the fields 3. Each group can be expanded/collapsed by clicking on a link "(Fewer|More) Options" which sits right next to the group title.
5
2195
by: gregmercer | last post by:
I have the following html sample, where I'd like to have a show and hide two divs, one replacing the other. Following these two divs is a third div (the bluediv) which I would like to have placed right up directly below to the first or second div, depending on which is showing. If you load the html in Firefox, and then click on the "Edit" link you can see that the first div is hidden, the second div is shown, however the third div is...
2
3927
by: Kevin | last post by:
I've got a problem where I need to know the value of a hidden field inside a repeater once a button is clicked. Ths code inside my repeater looks like this: <input id="conf_num" type="hidden" value=<%# trim(Container.DataItem("confirm_num"))%> name="conf_num" runat="server" /> <asp:ImageButton ImageUrl="images/send_conf.gif" OnClick="ConfSend_Click" runat="server" />
3
1800
by: Tom | last post by:
Sorry... new to this. I trying to figure out how to do a page redirect when someone clicks a treeview node. Does someone have a code snippet for this?
4
5086
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. Thanks Hans
5
2390
by: graphicsxp | last post by:
Hi, I have can upload a file to the server from my aspx page using the uploadfile control. When the user click on submit I'd like to show an animated gif while the file is being uploaded. But how can I know when the file was uploaded and I can stop showing the animation ? The way I've done it: I have a multiview control. view1 -> upload interface view2 -> animation while uploading
6
3888
by: =?Utf-8?B?L2Rldi9udWxs?= | last post by:
Hello, i am using visual studio 2003 enterprise architect version. I am making apps for the .Net framework 1.1. While testing an interface, i discovered something strange. In this application we have a standard toolbar that is at the top of the form window. It contains about 8 buttons that use images from an imagelist. Sometimes we hide buttons thru the code. When a button is hidden, i assumed that it wasn't clickable. It appears
5
1988
by: anonymousstar | last post by:
Hi all, I am new to these forums and decided to join one (this one) after 5 days of researching to try and solve my problem. I am creating a booking type of calendar. It will be run by an oracle database. From the front end a user will see all the dates that are available (green cells), dates that are pending (orange cells) and dates that are booked (red cells); the user will then click on the dates that are available they want to book,...
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8035
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.