Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-15-2005, 04:55 AM   PM User | #1
tuna
New to the CF scene

 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tuna is an unknown quantity at this point
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..
tuna is offline   Reply With Quote
Old 09-15-2005, 07:56 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,032
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 09-15-2005, 08:26 AM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,353
Thanks: 3
Thanked 456 Times in 443 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
http://homepage.ntlworld.com/vwphill...geScroller.htm
vwphillips is offline   Reply With Quote
Old 09-15-2005, 01:25 PM   PM User | #4
tuna
New to the CF scene

 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tuna is an unknown quantity at this point
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..
tuna is offline   Reply With Quote
Old 09-15-2005, 01:48 PM   PM User | #5
rm-f
Regular Coder

 
Join Date: Aug 2005
Location: Toronto, ON, Canada
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
rm-f is an unknown quantity at this point
Use OO aproach, so you can instantiate an object as many times as you need.
__________________
rm -f /
rm-f is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:17 PM.


Advertisement
Log in to turn off these ads.