Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6549471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:05:50+00:00 2026-05-25T12:05:50+00:00

This script has been running over at waterbirds.org for years. Now it’s broken for

  • 0

This script has been running over at waterbirds.org for years. Now it’s broken for some reason. It throws a “Cannot read property ‘src’ of undefined” error and I’ve tracked it down to preLoad[j].src (first line of runSlideShow function) as the problem because I can put a image link address there and it works. Any idea what’s causing the problem?

// Waterbird Society Theme for WordPress
// Rotating image banner applet
//
// Usage:
//<body onLoad='rotate_banner(slideShowSpeed, "Image1.jpg", "Image2.jpg"...)'>



var slideShowSpeed;
var j = 0;
var p;
var preLoad = new Array();

function rotate_banner() {
    var args = rotate_banner.arguments;
    slideShowSpeed = Number(args[0]);
    p = args.length;
    for (i = 0; i < p-1; i++) {
        preLoad[i] = new Image();
        preLoad[i].src = args[i+1];
    }
    runSlideShow();
}

function runSlideShow() {
    document.images['SlideShow'].src = preLoad[j].src;
    j++;

    if (j > (preLoad.length - 1)) j = 0;

    t = setTimeout('runSlideShow()', slideShowSpeed*1000);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:05:51+00:00Added an answer on May 25, 2026 at 12:05 pm

    Everything is alright with your code except for it is run globally so all var declarations create global variables.

    The exact issue on waterbirds.org is that j variable is defined somewhere before and by the moment it comes to preLoad[j] j equals 96, and preload[96] is really undefined.

    Wrap your banner in anonymous self-executing function, for example, to make vars local, and you’re done:

    (function(){
    
    var slideShowSpeed;
    var j = 0;
    var p;
    var preLoad = new Array();
    
    // to keep rotate_banner global, save it as a property of window object
    window.rotate_banner = function() {
        var args = rotate_banner.arguments;
        slideShowSpeed = Number(args[0]);
        p = args.length;
        for (i = 0; i < p-1; i++) {
            preLoad[i] = new Image();
            preLoad[i].src = args[i+1];
        }
        runSlideShow();
    }
    
    function runSlideShow() {
        document.images['SlideShow'].src = preLoad[j].src;
        j++;
    
        if (j > (preLoad.length - 1)) j = 0;
    
        t = setTimeout('runSlideShow()', slideShowSpeed*1000);
    }
    
    })()
    

    And remember: global variables are evil! =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A php script is giving this array (which has been passed through json_encode() )
I've got a bash script running in Cygwin whose output has been redirected to
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
http://steph.net23.net/work.php here is my test link. This page has a jquery script in it
What I'm trying to achieve: 1) http://localhost/en/script.php?param1=random is mapped to http://localhost/script.php?param1=random&language=English This has to
Sorry if this has been asked before, I did check but couldn't find anything...
I am testing a php script that has been developed on an OS-X system
I know this has been asked but I'm still confounded. I'm trying to build
I am sure this has been asked a ton of times, but would appreciate
I've been pulling my hear out over this problem for a few hours yesterday:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.