PDA

View Full Version : Pausing up-down scroller - Undefined



drk2cmp
04-28-2006, 03:22 AM
Script: DD Pausing Up-Down Scroller
http://dynamicdrive.com/dynamicindex2/crosstick.htm

I am experiencing a problem with the Pausing Up-Down Scroller.

I have it cycling through headlines pulled from a mysql database, and it does just fine, except that the first headline is always 'undefined'. I read through the responses concerning 'undefined' and changed the var i to var xbt, but I'm still experiencing the same problem, both in Firefox 1.0.7 and IE 6.0. Any ideas? :confused:

The page is http://mothercatherinespalding.k12.md.us/sas
(http://mothercatherinespalding.k12.md.us/sas)
The Javascript file is http://mothercatherinespalding.k12.md.us/sas/scroller.js

PS - It's still a work in progress.

~Drk2cmp

jscheuer1
04-28-2006, 05:54 AM
I don't know if this is hard coded into your page or generated via the method you mention but, this:


<script type="text/javascript">
var pausecontent=new Array()
pausecontent[1]='Headline (2)'
pausecontent[2]='Headline (1)'
pausecontent[3]='Headline (1)'
</script>

appears as a part of the source code on:

http://www.mothercatherinespalding.k12.md.us/sas/

You need to have a pausecontent[0], otherwise it will be undefined, from the demo page:



var pausecontent=new Array()
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'

drk2cmp
04-28-2006, 12:34 PM
Computers start with number 0 - How could I have been so blind. That's fixed the problem. Thanks for the advice, jscheuer1.

I have two test headlines at the moment - the script cycles 1, 2, 2, 1, 1, 2...

How can I change it to cycle 1, 2, 1, 2, 1...?

jscheuer1
04-28-2006, 07:23 PM
<script type="text/javascript">
var pausecontent=new Array()
pausecontent[0]='Headline (1)'
pausecontent[1]='Headline (2)'
</script>

iggy
09-11-2006, 04:24 AM
hi..i am also having the same problem with the script.
fyi, my thread starts with [0], retriving from db as well.
it seems that i only get the undefined value when there's only one item to be displayed.

i even tested with hardcoded values such as
<script language="Javascript">
var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
pausecontent2[1]='<a href="http://www.javascriptkit.com">235325</a><br />sfasfsaf'
</script>

--> this one works fine. but if it's

<script language="Javascript">
var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
</script>

--> it will return the JavaScript Kit .... and followed by undefined.

anyone?

jscheuer1
09-11-2006, 04:39 AM
For this script to work, it needs two items. If there is only one, the only options I can think of (still using the script) would be to use the same item twice or to have the second one be blank or the name of the site or some stock thing.

You could also choose to have, if there is only one item, to skip the script and just present the item as static content.

If you are generating the content, as you say, you could deal with that server side. In the script you could do something like:


if (!pausecontent2[1])
pausecontent2[1]=" ";

Have that right after the array. You could put whatever you want in place of the space or just leave it as is. For the same item twice:


if (!pausecontent2[1])
pausecontent2[1]=pausecontent2[0];

iggy
09-11-2006, 06:25 AM
Hi,

Thanks for the reply. I browsed through the script again after posting and realised that it does require 2 items for it to be displayed nicely. So when there's only one item, the second one is absent and thus displayed as undefined.

I tried (kinda cheated :P) by assigning a blank item if there is only one item retrieved from db.

<script language="Javascript">
var pausecontent2=new Array()
pausecontent2[0]='<a class="pscroller2" href="..">Item 1</a>'
pausecontent2[1]=''

new pausescroller(pausecontent2, "pscroller2", "pscroller2", 2000)
</script>

it works fine now.

thanks again for the help.. :D

Twey
09-11-2006, 06:26 AM
Didn't somebody fix this at one point?

jscheuer1
09-11-2006, 09:20 AM
Well, the old script, which wasn't even OO, did have some odd problems with the undefined but, that was under certain circumstances in certain browsers (both varied). DD took care of all that but, this is the first time that there ever has been a problem because there was only one entry in the array. I like my solution as, you can choose what to show. It looks pretty good, just repeating the one item:


var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.news.com">News.com: Technology and business reports</a>'

if (!pausecontent2[1])
pausecontent2[1]=pausecontent2[0];

This would be with the red part generated server side.