/    Sign up×
Community /Pin to ProfileBookmark

Two of the Same News Scrollers on One Page

I have a question, I am using this News Scroller on my page,

<style type=”text/css”>
<!–
.newsTxt1 {
font-size: .8em;
font-family: verdana, helvetica, arial, sans-serif;
}
.newsTxt2 {
font-size: 1em;
font-family: verdana, helvetica, arial, sans-serif;
font-weight: bold;
}
–>
</style>
<script type=”text/javascript”>
<!–
/* This script and many more are available free online at
The JavaScript Source!! [url]http://javascript.internet.com[/url]
Created by: Robert Suppenbach ::webdevel.deezhosts.net *
/

var toScroll=new Array()
var ie=document.all
var dom=document.getElementById
var firstNews_obj;
var secondNews_obj;

function newsScroll(name){
var c=this; c.name=name; c.mc=0; c.i=2;
return this;
}

newsScroll.prototype.addItem = function(text,link,font,fontSize,fontStyle){
var c = this;
if (link !=”){
if (font != ”)
toScroll[c.mc]=”<a href='”+link+”‘><font face='”+font+”‘ size='”+fontSize+”‘ Class='”+fontStyle+”‘>”+text+”</font></a>”;
else
toScroll[c.mc]=”<a href='”+link+”‘><font Class='”+fontStyle+”‘>”+text+”</font></a>”;
}
else {
if (font != ”)
toScroll[c.mc]=”<font face='”+font+”‘ size='”+fontSize+”‘ Class='”+fontStyle+”‘>”+text+”</font>”;
else
toScroll[c.mc]=”<font Class='”+fontStyle+”‘>”+text+”</font>”;
}
c.mc++;
}

newsScroll.prototype.construct = function(){
var c = this; theWidth = c.scrollerwidth; theHeight=c.scrollerheight; thebgColor = c.scrollerbgcolor; theBackground =c.scrollerbackground; theDelay=c.scrollerdelay;
scroll_obj=eval(c.name);

if (ie||dom){
document.writeln(‘<div id=”main2″ style=”position:relative;width:’+theWidth+’;height:’+theHeight+’;overflow:hidden;background-color:’+thebgColor+’ ;background-image:url(‘+theBackground+’)”>’)
document.writeln(‘<div style=”position:absolute;width:’+theWidth+’;height:’+theHeight+’;clip:rect(0 ‘+theWidth+’ ‘+theHeight+’ 0);left:0;top:0″>’)
document.writeln(‘<div id=”firstNews” style=”position:absolute;width:’+theWidth+’;left:0;top:1″>’)
document.write(toScroll[0])
document.writeln(‘</div>’)
document.writeln(‘<div id=”secondNews” style=”position:absolute;width:’+theWidth+’;left:0;top:0;visibility:hidden”>’)
document.write(toScroll[dyndetermine=(toScroll.length==1)? 0 : 1])
document.writeln(‘</div>’)
document.writeln(‘</div>’)
document.writeln(‘</div>’)
}
}

newsScroll.prototype.move = function(whichdiv){
var c = this; theDelay = c.scrollerdelay; theHeight = c.scrollerheight;
scroll_obj=eval(c.name);
tdiv=eval(whichdiv)

if (parseInt(tdiv.style.top)>0&&parseInt(tdiv.style.top)<=5){
tdiv.style.top=0+”px”
setTimeout(“scroll_obj.move(tdiv)”,theDelay)
setTimeout(“scroll_obj.move2(secondNews_obj)”,theDelay)
//document.write(‘Got Milk?’)
return
}
if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1){
tdiv.style.top=parseInt(tdiv.style.top)-5+”px”
setTimeout(“scroll_obj.move(tdiv)”,50)
}
else {
tdiv.style.top=parseInt(theHeight)+”px”
tdiv.innerHTML=toScroll[c.i]
if (c.i==toScroll.length-1)
c.i=0
else
c.i++
}
}

newsScroll.prototype.move2 = function(whichdiv){
var c = this; theDelay = c.scrollerdelay; theHeight= c.scrollerheight;
scroll_obj=eval(c.name);
tdiv2=eval(whichdiv)

if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5){
tdiv2.style.top=0+”px”
setTimeout(“scroll_obj.move2(tdiv2)”,theDelay)
setTimeout(“scroll_obj.move(firstNews_obj)”,theDelay)
return
}
if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1){
tdiv2.style.top=parseInt(tdiv2.style.top)-5+”px”
setTimeout(“scroll_obj.move2(secondNews_obj)”,50)
}
else {
tdiv2.style.top=parseInt(theHeight)+”px”
tdiv2.innerHTML=toScroll[c.i]
if (c.i==toScroll.length-1)
c.i=0
else
c.i++
}
}

newsScroll.prototype.startScroll = function(){
var c = this;
scroll_obj=eval(c.name);

if (toScroll.length >2)
c.i = 2;
else
c.i = 0;

firstNews_obj=ie? firstNews : document.getElementById(“firstNews”)
secondNews_obj=ie? secondNews : document.getElementById(“secondNews”)
setTimeout(“scroll_obj.move(firstNews_obj)”,c.scrollerDelay);
secondNews_obj.style.top=theHeight;
secondNews_obj.style.visibility=’visible’
}
–>
</script>
<div align=”center”>
<script type=”text/javascript”>
<!– Begin
theNews=new newsScroll(“theNews”); //create our newsScroller object
theNews.scrollerdelay = 5000; // pausetime 3000 = 3 Seconds
theNews.scrollerwidth = 225; // the width of the box
theNews.scrollerheight = 350; // the height of the box
theNews.scrollerbgcolor = ”; // the box background color
theNews.scrollerbackground = ”; // Set to blank if you don’t want to use a background image

//******************************************************************
//
// The addItem method below has 5 variables and is formated as follows:
// addItem (text,link,font,fontSize,fontStyle)
// text – the text to be displayed.
// link – (optional) website, or page to link news item to.
// font – (optional) Font face to use on item.
// fontSize – (optional) size in pt format
// i.e. 1=8pt, 2=10pt, 3=12pt and so on.
// fontStyle – (optional) css style to assign to font. You can use the class name.
//
//*
**
***************************************************************

theNews.addItem(‘Welcome to <em>JavaScript Source</em><br><br>Feel free to use any of the scripts listed here<br>(<em>This item contains a link.</em>)’,’http://javascript.internet.com’,”,”,’newsTxt2′);
theNews.addItem(‘We have scripts for banner ads, graphics, forms, navigation, cookies, and more!’,”,”,”,’newsTxt1′);
theNews.addItem(‘This scoller can be used to post current news, sales items, or new content. The listings can contain links or can just be text, like this one.’,”,”,”,”);
theNews.addItem(‘You can set the speed and size of the scroller box to be used. Add as many items as you like!’,”,”,”,’newsTxt1′);

// the next 2 lines construct the news box, and start the scroller
theNews.construct();
theNews.startScroll();
// End –>
</script>
</div>

It works beautifully if I only have one scroller on the page, however, when I add a second scroller I get all kinds of object errors that I do not understand, can someone help me do this?

Please do not lecture me on the annoyance of to many scrollers, I understand this and have a purpose for this particular method of information sharing.

If you could help me run a second scroller on this page I would appriciate it, I have already tried changing the name of the object from theNews to Header giving my two scrollers different names but that does not work.

Also, I am using these on PHP pages, and I am including them through the php include method ( if that makes any difference. ) the scroller code itself is contained in an .html file.

Thank you for your help ahead of time!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 20.2006 — Considering that your post was viewed 153 times (but noone answered it), it might help if you reviewed the posting guidelines you'll find in the sticky threads at the top of this forum -- which are inteded to [u][i]help you[/i][/u]; [b]not[/b] cruelly criticize you. ? However, to summarize a few of them (in no particular order):
[list=1]
  • [*]A lack of specific information on a particular problem usually causes the casual visitor to bypass your post -- for example, no mention of actual error message text and/or no indication as to which line of code is the problem. Why? Because, most people don't like to take their time to play 20 questions in an attempt to find out more.

    [indent][b]Hint:[/b] To find error messages in IE, display the status bar and, at the left side, double-click the little, yellow triangle (if there is one). To find error messages in NS or FF, use the menu bar to open the Tools / JavaScript Console dialog box.[/indent]

  • [*]A big, long description, a lot of source code (especially, the unexplained kind), and/or links to other resources usually discourage the casual visitor from attempting an answer. Why? Because it would require too much of the visitor's time to figure out what it's all about. Visitors like to see that the OP (original poster) has done their own homework on the issue.

  • [*]Asking for multiple answers/solutions, in the same thread, can also cause the casual visitor to bypass your post. Why? A visitor may only wish to use their time to answer just one question -- but, by answering the one, then the OP will automatically expect additional answers from them.

  • [*]Almost any post, without at least [u][i]some[/i][/u] accompanying code, may discourage the casual visitor from answering -- especially if it seems like, or is actually stated, that a complete solution is desired. Why? Because it takes a lot more of the visitor's time to develop a complete solution.
  • [/list]

    Did you notice repeated mention of the "casual visitor" and [u][i]their time[/i][/u]? You see, this site is [b][u][i]not[/i][/u][/b] intended as a place to obtain free contract-programming services. Thus, every person that answers questions here is simply a visitor to this site -- as you were. Hence, if you're really, really new to JavaScript, or haven't ever made the time to take a complete [URL=http://www.webreference.com/programming/javascript/diaries/]JavaScript Tutorial[/URL], then your best course of action is to start there.

    So, if you'd like to post again, and resolve these issues, then I'm sure someone would like to help answer your question -- including myself! ?

    Cheers.
    Copy linkTweet thisAlerts:
    @phpnoviceApr 20.2006 — Considering that your post was viewed 160 times (but noone answered it), it might help if you reviewed the posting guidelines you'll find in the sticky threads at the top of this forum -- which are inteded to [u][i]help you[/i][/u]; [b]not[/b] cruelly criticize you. ? However, to summarize a few of them (in no particular order):
    [list=1]
  • [*]A lack of specific information on a particular problem usually causes the casual visitor to bypass your post -- for example, no mention of actual error message text and/or no indication as to which line of code is the problem. Why? Because, most people don't like to take their time to play 20 questions in an attempt to find out more.

    [indent][b]Hint:[/b] To find error messages in IE, display the status bar and, at the left side, double-click the little, yellow triangle (if there is one). To find error messages in NS or FF, use the menu bar to open the Tools / JavaScript Console dialog box.[/indent]

  • [*]A big, long description, a lot of source code (especially, the unexplained kind), and/or links to other resources usually discourage the casual visitor from attempting an answer. Why? Because it would require too much of the visitor's time to figure out what it's all about. Visitors like to see that the OP (original poster) has done their own homework on the issue.

  • [*]Asking for multiple answers/solutions, in the same thread, can also cause the casual visitor to bypass your post. Why? A visitor may only wish to use their time to answer just one question -- but, by answering the one, then the OP will automatically expect additional answers from them.

  • [*]Almost any post, without at least [u][i]some[/i][/u] accompanying code, may discourage the casual visitor from answering -- especially if it seems like, or is actually stated, that a complete solution is desired. Why? Because it takes a lot more of the visitor's time to develop a complete solution.
  • [/list]

    Did you notice repeated mention of the "casual visitor" and [u][i]their time[/i][/u]? You see, this site is [b][u][i]not[/i][/u][/b] intended as a place to obtain free contract-programming services. Thus, every person that answers questions here is simply a visitor to this site -- as you were. Hence, if you're really, really new to JavaScript, or haven't ever made the time to take a complete [URL=http://www.webreference.com/programming/javascript/diaries/]JavaScript Tutorial[/URL], then your best course of action is to start there.

    So, if you'd like to post again, and resolve these issues, then I'm sure someone would like to help answer your question -- including myself! ?

    Cheers.
    ×

    Success!

    Help @AdolphousC spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...