Results 1 to 9 of 9

Thread: Pausing up-down scroller - Undefined

  1. #1
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Pausing up-down scroller - Undefined

    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?

    The page is http://mothercatherinespalding.k12.md.us/sas

    The Javascript file is http://mothercatherinespalding.k12.m...as/scroller.js

    PS - It's still a work in progress.

    ~Drk2cmp

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't know if this is hard coded into your page or generated via the method you mention but, this:

    Code:
    		<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:

    Code:
    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.'
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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...?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    		<script type="text/javascript">
    		var pausecontent=new Array()
    pausecontent[0]='Headline (1)'
    pausecontent[1]='Headline (2)'
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

    Code:
    if (!pausecontent2[1])
    pausecontent2[1]=pausecontent2[0];
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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..

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Didn't somebody fix this at one point?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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