Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Location
    Pennsylvania
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Stop Automatic Page Scrolling with OnClick="toggleItem('box04')

    Code:
        function getItem(id)
        {
            var itm = false;
            if(document.getElementById)
                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);
    
            if(!itm)
                return false;
    
            if(itm.style.display == 'none')
                itm.style.display = 'block';
            else
                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:
    Code:
    <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 
          Links</font></strong></td>
    The thing being controlled:
    Code:
    	<td width="261" height="131" colspan="87" valign="top" bgcolor="#CCCCCC" id="box04" style="border:solid 2px #004501;">
    			<ul>
    				<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>
    			</ul>
    		</td>
    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?

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your problem is here: href="#"

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

    .....Willy

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

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Location
    Pennsylvania
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by Willy Duitt
    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:

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

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

    Thanks!

  • #4
    New to the CF scene
    Join Date
    Dec 2004
    Location
    Pennsylvania
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Never mind about my previous post, it was this:

    Code:
    <a onclick="toggleItem('box01')">
    :-)

    Thanks a bunch!!!

    :-)

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I was thinking of: <a href="#" onclick="return toggleItem('box04')">

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

    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •