Toby Brown

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromToby Brown
ToMe
SubjectCollapsable FAQ list
Date13 March 2004 23:06
Hi, I've spent too much time searching, I'm hoping you'll have an
immediate answer from seeing some of the scripts on your site.

This is what I need to do:
I have an HTML page with a long list of FAQ questions and answers. I need
to be able to just display the questions initially and if someone clicks
on it, the text of the answer just expands below it. When another question
is clicked upon then the previous questions answer hides again and the new
answer expands. So basically a collapsable list of questions and answers.

I hope I've explained myself enough, I know this sort of thing should be
possible I just haven't been able to work it out yet and I'd apreciate
your help/guidance in any way.

Many thanks,

Toby
FromMe
ToToby Brown
SubjectRe: Collapsable FAQ list
Date14 March 2004 15:39
Toby,

Easy enough.

Make each one of the titles a paragraph (for example).
Wrap each answer in a DIV, and give it a unique ID.
Onload, run a script to collapse the answers.
When the paragraphs are clicked, toggle the display style of the 
relevant answer DIV.

I recommend using sequential numbers in the ID to make collapsing 
easier. (in the example below, the first id should be ans0, the second
should be ans1 etc.)

HTML:
<p style="cursor:help;" onclick="toggleInfo('ans0');">
 Some question
</p>
<div id="ans0">
 <p>answer</p>
 <p>More of the answer</p>
</div>

Script:
<script type="text/javascript"><!--
var storedDiv = null;
function getDiv(oID) {
 if(document.getElementById) {
  return document.getElementById(oID);
 } else if( document.all ) {
  return document.all[oID];
 } else { return null; }
}
window.onload = function () {
 for( var i = 0, y; y = getDiv('ans'+i); i++ ) {
  y.style.display = 'none';
 }
};
function toggleInfo(oID) {
 var oDiv = getDiv(oID); if( !oDiv ) { return; }
 oDiv.style.display = (oDiv.style.display=='none') ? 'block' : 'none';
 if( storedDiv && storedDiv != oDiv ) { storedDiv.style.display = 'none';
 } storedDiv = oDiv;
}
//--></script>


I've not tested this but it should work first try :)

hope this is useful.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromToby Brown
ToMe
SubjectRe: Collapsable FAQ list
Date15 March 2004 13:31
That works just fine, many thanks Mark.
FromToby Brown
ToMe
SubjectDynamically change select field with Imagemap
Date12 May 2005 11:49
Hi,

You've helped me out before last year so I'm hoping you can help me again!

I have been unable to find anything on this while searching the net so it
may not even be possible but here's what I need to do: I have an imagemap
and a form on the same html page, the regions on the imagemap correspond to
the regions in a select field within my form, is it possible to dynamically
change the 'selected' region in the select field(drop-down list) by clicking
on a region of the imagemap?

I'd be grateful if you could point me in the right direction,

Thanks,
Toby
FromMe
ToToby Brown
SubjectRe: Dynamically change select field with Imagemap
Date12 May 2005 13:31
Toby,

> is it possible to dynamically
> change the 'selected' region in the select field(drop-down list) by
> clicking on a region of the imagemap?

yes, using JavaScript.

function setSelectValue(oVal) {
    var oSel = document.myform.myselect;
    for( var i = 0; i < oSel.options.length; i++ ) {
        if( oSel.options[i].value == oVal ) {
            oSel.options[i].selected = true;
        }
    }
}
...
<area href="javascript:setSelectValue('foo');" ...>
...
<form name="myform">
<select name="myselect">
    <option value="first">Hello</option>
    <option value="foo">World</option>
    ...
</select>
</form>
FromToby Brown
ToMe
SubjectRe: Dynamically change select field with Imagemap
Date12 May 2005 15:05
Thanks for all your help, you've got me out of a hole!
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.