Jump to content

Using OnClick on my page


Recommended Posts

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')">•     Question15?</a></p> 
<blockquote>
<div id='QUESTION15' style="display:none"> 
  <p>Answer15.</p>
  </div>
</blockquote>

Any help is appreciated.

Link to comment
Share on other sites

  • 2 weeks later...

<html> 
<head> 
<title>Untitled</title> 
<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; 
} 
</script> 
</head> 
<body> 
<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> 
</div> 
</body>
</html>

 

hope this helps... Shaun

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.