Gossamer Forum
Home : General : Internet Technologies :

News Ticker...

Quote Reply
News Ticker...
Hi,

I've just been working on a News Ticker (to go on a site) using the BBC's XML feed.

Now, the script was a piece of cake to write. However, getting the news to actually show now is prooving to be more of a PITA :/

The outputted code looks like;

Code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />

</head>

<body>
<div class="ticki"><a id="tickerAnchor" href="#" target="_top" class="tickl"></a></div>
<script language="JavaScript" type="text/javascript">
<!--
// Ticker startup
function startTicker()
{
// Define run time values
theCurrentStory = -1;
theCurrentLength = 0;
// Locate base objects
if (document.getElementById) {
theAnchorObject = document.getElementById("tickerAnchor");
runTheTicker();
}
else {
document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
return true;
}
}
// Ticker main run loop
function runTheTicker()
{
var myTimeout;
// Go for the next story data block
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/&quot;/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = "<span class="tickls">" + theLeadString + "</span>";
}
// Stuff the current ticker text into the anchor
theAnchorObject.innerHTML = thePrefix +
theStorySummary.substring(0,theCurrentLength) + whatWidget();
// Modify the length for the substring and define the timer
if(theCurrentLength != theStorySummary.length)
{
theCurrentLength++;
myTimeout = theCharacterTimeout;
}
else
{
theCurrentLength = 0;
myTimeout = theStoryTimeout;
}
// Call up the next cycle of the ticker
setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
if(theCurrentLength == theStorySummary.length)
{
return theWidgetNone;
}

if((theCurrentLength % 2) == 1)
{
return theWidgetOne;
}
else
{
return theWidgetTwo;
}
}
// -->
</script>


<script language="JavaScript" type="text/javascript">
<!--

var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "LATEST:&nbsp;";

var theSummaries = new Array();
var theSiteLinks = new Array();

var theItemCount = 10;



theSummaries[0] = "Three killed as storms batter UK";
theSiteLinks[0] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4164613.stm";

theSummaries[1] = "Blair to face MPs amid feud talk";
theSiteLinks[1] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk_politics/4166625.stm";

theSummaries[2] = "Alarming ignorance of cancer risk";
theSiteLinks[2] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/health/4164131.stm";

theSummaries[3] = "Boscastle awaits flooding report";
theSiteLinks[3] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166895.stm";

theSummaries[4] = "'Errors' doomed first Dome sale";
theSiteLinks[4] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk_politics/4165767.stm";

theSummaries[5] = "Police launch Class A drugs blitz";
theSiteLinks[5] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166925.stm";

theSummaries[6] = "Businessman takes top MI6 job";
theSiteLinks[6] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/uk/4166941.stm";

theSummaries[7] = "'vCJD timebomb' fears discounted";
theSiteLinks[7] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/health/4162749.stm";

theSummaries[8] = "Greer attacks 'bully' Big Brother";
theSiteLinks[8] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/entertainment/tv_and_radio/4165101.stm";

theSummaries[9] = "Football: Morientes close to move";
theSiteLinks[9] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/sport1/hi/football/teams/l/liverpool/4127559.stm";

theSummaries[10] = "Tennis: Henman winning start";
theSiteLinks[10] = "http://news.bbc.co.uk/go/click/rss/0.91/public/-/sport1/hi/tennis/4164273.stm";



startTicker();

//-->
</script>


</body>
</html>

Can anyone see any stupid mistakes?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

Last edited by:

Andy: Jan 12, 2005, 1:05 AM
Quote Reply
Re: [Andy] News Ticker... In reply to
Wild guess, but could it be this:

var theItemCount = 10;


You have 0-10 in your array which is 11 items (?)
Quote Reply
Re: [Watts] News Ticker... In reply to
Thanks for the try... didn't work though :

The actual error (which wasn't being reported earlier), is something about "line 46", which is;

Code:
45 theStorySummary.substring(0,theCurrentLength) + whatWidget();
46 // Modify the length for the substring and define the timer
47 if(theCurrentLength != theStorySummary.length)

I'm not really a JS expert though Frown

TIA!

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] News Ticker... In reply to
Andy, what is the verbatim JS error message?

----
Cheers,

Dan
Principal

Virtual Solutions
Quote Reply
Re: [dan] News Ticker... In reply to
Hi,

I can't copy+paste the exact message, but its along the lines of;

Line 44
Char 35
Error: Expected ';'

..and;

Line 146
Char 2
Error: Object Expected

Probably something silly... but my JS skills have a little to be desired =)

TIA

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] News Ticker... In reply to
Is:

theAnchorObject.innerHTML = thePrefix + theStorySummary.substring(0,theCurrentLength) + whatWidget();

on the same line - error message seems to indicate that it is broken up over 2 lines.

----
Cheers,

Dan
Principal

Virtual Solutions
Quote Reply
Re: [dan] News Ticker... In reply to
Thanks. I think that may well be it =)

The stupid server has gone offline (or is very busy) at the moment... which is a PITA :'( I guess I'll have to take a look tomorrow.

Thanks again.. and lets hope that fixes it <G>

Cheres

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] News Ticker... In reply to
If not, if you can post a URL to the page, it would be helpful. Dang servers, you must have the ML-Chip installed. Murphy's Law Chip =) I don't know why, but I keep on upgrading mine ;=)

----
Cheers,

Dan
Principal

Virtual Solutions
Quote Reply
Re: [Andy] News Ticker... In reply to
Also check a line or two above that for this:

Code:
thePrefix = "<span class="tickls">" + theLeadString + "</span>";

You might need to escape the extra "'s in there:

Code:
thePrefix = "<span class=\"tickls\">" + theLeadString + "</span>";

~Charlie
Quote Reply
Re: [Chaz] News Ticker... In reply to
Just tested and that did the trick :)

~Charlie
Quote Reply
Re: [Chaz] News Ticker... In reply to
Thanks... that worked a beauty :)

Turned out to be the way the Perl script was interpreting it. i.e, it was set to show as;

thePrefix = "<span class=\"tickls\">" + theLeadString + "</span>";

... but I had to use the following in the end;

thePrefix = "<span class=\\\"tickls\\\">" + theLeadString + "</span>";

Thanks for the pointer Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates