View Full Version : Simple VBscript acting funny

09-22-2005, 04:47 PM
I have a simple vbscript to make text appear and disappear with the click of a link. I am using this on a FAQ page so you can quickly go down the list of questions and just open the text to the answer you want.

Anyways - it works fine except if you are at the bottom of the page and click the link it jumps the browser to the top - not sure why it is doing that. :confused:

Here is the script:
<script LANGUAGE="VBScript">
sub show (id)
if id.style.display = "" then
id.style.display = "none"
id.style.display = ""
end if
end sub


Here is a link:
<a href="#" onclick="show(q1)">Question here</a>

Here is the span this link would open:
<span id="q1" style="display: none">Answer here</span>

LIke I said it works fine except it wants to kick the browser up the top of page if you are at the bottom whne you click.

Any thoughts?

09-22-2005, 04:55 PM
You do realize vbscript on the client is only supported by IE, so those of us who won't or can't use it are screwed, right?

<a href="#" onclick="show(q1); return false;">Question here</a>

It jumps to the top because it follows the link. Put the return false in there to stop that.

09-22-2005, 09:10 PM
Yes, I knew that - this is acutally an in-house FAQ on a Extranet site and the company uses IE exclusively so I figured why not.

Anyways, I tried adding return false to the onclick attribute, but it stopped the function from working and it was still following the link.

So, I think now it may be conflicting with other scripts on the page so I may have to come at this another way.

09-22-2005, 09:22 PM
In case your curious - what I decided to do was just go with it and put anchors at each question so when it follows the link it doesn't go anywhere - not an ideal coding solution but it gives the desired results - so I'm happy. :)

09-23-2005, 09:50 AM
It's very easy if you do it in javascript.

<script type="text/javascript">
function show(id){
var ans = document.getElementById(id);
ans.style.display = (ans.style.display=="none") ? "inline":"none";
return false;
<a href="#" onclick="return show('q1');">Question here</a>
<span id="q1" style="display: none">Answer here</span>

09-23-2005, 04:03 PM
The javascript method you offered does not have the same conflicts with my other scripts so I will employ it on my page - thanks! :thumbsup: