Jump to content


Using OnClick on my page

  • Please log in to reply
1 reply to this topic

#1 bernie.nmsu

  • Members
  • PipPip
  • Member
  • 22 posts

Posted 14 March 2005 - 07:04 PM

I am developing a FAQ page. I have it set up to where the page only displays common questions. Once the user selects the question, the answer displays right below it. When the user clicks on the question again, the answer becomes hidden. I have the basic functionality to work fine, except that when get to the bottom my FAQ list and you click on the question to display the answer, the focus gets placed back to the top of the page rather than the new information that just got displayed. I'm already using onClick to run my function to show the text, but I also need it to focus on the answer.
<p><a href="#" id="moreLink15" onClick="return showAndHide('QUESTION15')">•&nbsp;    Question15?</a></p> 
 <div id='QUESTION15' style="display:none"> 
Any help is appreciated.

#2 Shaun

  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationMidlands

Posted 26 March 2005 - 10:27 PM

<script language="JavaScript"> 
function showAndHide(theId) { 
  var el = document.getElementById(theId); 
  var link = document.getElementById("moreLink"); 

  if (el.style.display=="none") { 
     el.style.display="block"; //show element 
     link.innerHTML = "Hide Links..."; 
  else { 
     el.style.display="none"; //hide element 
     link.innerHTML = "More..."; 
  return false; 
<p><a id="moreLink1" href="#" onClick="return showAndHide('QUESTION1')">FAQ #1</a></p> 
<div id='QUESTION1' style="display:none"> 
ANSWER 1<br> 
ANSWER 1A</a><br> 
ANSWER 1B</a><br> 

hope this helps... Shaun

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users