View Full Version : Stop Automatic Page Scrolling with OnClick="toggleItem('box04')

12-19-2004, 11:41 PM
function getItem(id)
var itm = false;
itm = document.getElementById(id);
else if(document.all)
itm = document.all[id];
else if(document.layers)
itm = document.layers[id];

return itm;

function toggleItem(id)
itm = getItem(id);

return false;

if(itm.style.display == 'none')
itm.style.display = 'block';
itm.style.display = 'none';

return false;

That part is in the header, and this part is in the body:

This is the controller for the next part:

<td valign="top" background="images/test.jpg"><a href="#" onclick="toggleItem('box04')">
<img src="collapse/open.gif" border="0" onClick="close.gif" ></a><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Quick

The thing being controlled:

<td width="261" height="131" colspan="87" valign="top" bgcolor="#CCCCCC" id="box04" style="border:solid 2px #004501;">
<li><a href="http://www.google.com/" target="_out">http://www.google.com/</a></li>
<li><a href="http://www.shanahan.org/" target="_out">http://www.shanahan.org/</a></li>

My problem is that if you are viewing the page, there are many similar instances of the above, and if you scroll down and click one, it takes you to the top of the page. I want it to remain exactly where the user was. How would I do that?

Willy Duitt
12-19-2004, 11:50 PM
Your problem is here: href="#"

You need to return false to prevent the link from following the internal anchor...


BTW: What the heh is this: onClick="close.gif" ???

12-19-2004, 11:57 PM
Your problem is here: href="#"
BTW: What the heh is this: onClick="close.gif" ???

That changes the image to the image that it's closed...it minimizes/maximizes a "window" on a page...

And what should I do, have it look like this:

<a href="" onclick="toggleItem('box04')"> ?

Or maybe just
<a onclick="toggleItem('box04')"> ?


12-20-2004, 12:00 AM
Never mind about my previous post, it was this:

<a onclick="toggleItem('box01')">


Thanks a bunch!!!


Willy Duitt
12-20-2004, 12:26 AM
Actually, I was thinking of: <a href="#" onclick="return toggleItem('box04')">

But then again, I would advise using a span instead...