clear previous show function

This is a discussion on "clear previous show function" within the JavaScript Forum section. This forum, and the thread "clear previous show function are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 24th, 2007, 16:10
New Member
Join Date: Jan 2007
Location: newcastle
Age: 32
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
clear previous show function

Hi everyone - hoping some can help

Here is my code

<script>
function show( id )
{
if (document.getElementById(id).style.display == 'block')
{
document.getElementById(id).style.display = 'none';
}else
{
document.getElementById(id).style.display = 'block';
};
}
</script>

<span style="cursor:-moz-grab" onclick="show('r1m');">Will it cost me anything to join this site?</span>
</strong></div>
<div id="r1m" style="Display: None;">
<blockquote>No its free</blockquote>
</div>
<div id="r2l"><strong>
<span style="cursor:-moz-grab" onclick="show('r2m');">Who can join?</span>
</strong></div>
<div id="r2m" style="Display: None;">
<blockquote>Anyone aged 16 years or older with a mobile phone and access to the Internet can join.</blockquote>
</div>

As you can see the is from a faq section of code - where you click on the question and the answer is displayed below the question.
However once the question is clicked the question remains visible unless you click on the question again.
This is fine but what I also want is this - when you click on another question, the previous answer that has been displayed will disappear leaving only the current answer showing.

thanks

Tim
Reply With Quote

  #2 (permalink)  
Old Jan 24th, 2007, 21:08
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: clear previous show function

Add a global variable to your script, e.g.,
Code: Select all
   var lastShow;
then in your show function hide the last shown item, store the item you want to show for future reference, show the item.
Reply With Quote
Reply

Tags
show function

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript show/hide function danny322 JavaScript Forum 1 May 15th, 2008 12:46
all clear ltd littlebilly Free Web Site Critique 9 Aug 7th, 2007 21:50
How to reload the previous page? khwab JavaScript Forum 1 Aug 22nd, 2006 10:41
how do I get the previous value tllcll JavaScript Forum 1 Oct 24th, 2005 11:51
next previous GillBates Webforumz Suggestions and Feedback 4 Mar 4th, 2004 17:44


All times are GMT. The time now is 19:21.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43