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
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using the same script twice on the same Page

    hey. I've only scripted a couple times, and only read through the first few chapters of any javabooks or tutorials.

    I'm trying to use this "Scrollable content script" from Dynamic Drive more then once on my site, so I can have multiple text areas with scrollable text.

    How can I do this? Of course I tried just posting it twice, but that didn't work. I read some comment about using the <body> onload function, but I don't understand it enough to implement it.

    I also tried changing names, IDs, etc but none of it worked. Obviously I don't know what I'm doing.

    What happens when I just paste it twice, is they both show up, but the scroll buttons from both scripts only control the first content area.

    Code:
    <script type="text/javascript">
    
    /******************************************
    * Scrollable content script II- © Dynamic Drive (www.dynamicdrive.com)
    * Visit http://www.dynamicdrive.com/ for full source code
    * This notice must stay intact for use
    ******************************************/
    
    iens7=document.all||document.getElementById
    ns4=document.layers
    
    //specify speed of scroll (greater=faster)
    var speed=5
    
    if (iens7){
    document.write('<div id="container" style="position:relative;width:190px;height:200px;overflow:hidden">')
    document.write('<div id="content" style="position:absolute;width:185px;left:0;top:0">')
    }
    </script>
    
    <ilayer name="nscontainer" width=190 height=200 clip="0,0,190,200">
    <layer name="nscontent" width=190 height=200 visibility=hidden>
    
    <!--INSERT CONTENT HERE-->
    
    <!--END CONTENT-->
    
    </layer>
    </ilayer>
    
    <script language="JavaScript1.2">
    if (iens7)
    document.write('</div></div>')
    </script>
    
    <table width="190px"><td><p align="left">
    <a href="#" onMouseover="moveup()" onMouseout="clearTimeout(moveupvar)"><img src="up.gif" border=0></a>  <a href="#" onMouseover="movedown()" onMouseout="clearTimeout(movedownvar)"><img src="down.gif" border=0></a></p></td>
    </table>
    
    <script language="JavaScript1.2">
    if (iens7){
    var crossobj=document.getElementById? document.getElementById("content") : document.all.content
    var contentheight=crossobj.offsetHeight
    }
    else if (ns4){
    var crossobj=document.nscontainer.document.nscontent
    var contentheight=crossobj.clip.height
    }
    
    function movedown(){
    if (iens7&&parseInt(crossobj.style.top)>=(contentheight*(-1)+100))
    crossobj.style.top=parseInt(crossobj.style.top)-speed+"px"
    else if (ns4&&crossobj.top>=(contentheight*(-1)+100))
    crossobj.top-=speed
    movedownvar=setTimeout("movedown()",20)
    }
    
    function moveup(){
    if (iens7&&parseInt(crossobj.style.top)<=0)
    crossobj.style.top=parseInt(crossobj.style.top)+speed+"px"
    else if (ns4&&crossobj.top<=0)
    crossobj.top+=speed
    moveupvar=setTimeout("moveup()",20)
    
    }
    
    function getcontent_height(){
    if (iens7)
    contentheight=crossobj.offsetHeight
    else if (ns4)
    document.nscontainer.document.nscontent.visibility="show"
    }
    window.onload=getcontent_height
    </script>
    Sorry for posting the whole script, but I don't know what part I have to change.

    Thanks for any help!
    Last edited by tuna; 09-15-2005 at 05:03 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,895
    Thanks
    202
    Thanked 2,528 Times in 2,506 Posts
    This question has been asked a zillion times, and the solution is very well explained at

    http://www.javascriptkit.com/javatut...iplejava.shtml

    You cannot have two or more functions or global variables with the same name. So you need to change all of these in one of the scripts to (say) movedown2(), moveup2(), crossobj2 etc.

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,494
    Thanks
    3
    Thanked 499 Times in 486 Posts

  • #4
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M
    This question has been asked a zillion times, and the solution is very well explained at

    http://www.javascriptkit.com/javatut...iplejava.shtml

    You cannot have two or more functions or global variables with the same name. So you need to change all of these in one of the scripts to (say) movedown2(), moveup2(), crossobj2 etc.
    Yeah, I read that article, but didn't really understand!

    But I went through and changed every frick'n variable I could, and finally changed enough of them that it worked. Thanks!
    Last edited by tuna; 09-15-2005 at 01:34 PM.

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use OO aproach, so you can instantiate an object as many times as you need.
    rm -f /


  •  

    Posting Permissions

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