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 6624471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:39:28+00:00 2026-05-25T21:39:28+00:00

My code is very self explanatory. It is suppose to, after the page loads

  • 0

My code is very self explanatory. It is suppose to, after the page loads all necessary images, start looping through the same 5 images for the banner, with a 5 second delay in between. But, it doesn’t do anything when the page loads.

<script type="text/javascript">
var counter = 0;
var bannerList = new Array();
bannerList[0] = "/portfolio/1.jpg"
bannerList[1] = "/portfolio/2.jpg"
bannerList[2] = "/portfolio/3.jpg"
bannerList[3] = "/portfolio/4.jpg"
bannerList[4] = "/portfolio/5.jpg"

function bannerRotator(){
    if(counter > 4){
        counter = 0;
    }
    document.getElementById("slide").src = bannerList[counter];
    counter = counter + 1;
    var t=setTimeout("bannerRotator()", 2000);
}
</script>

Along with:

<body onLoad="bannerRotator();">

Can anyone see where I’m going wrong? Thanks for any help!

  • 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-25T21:39:28+00:00Added an answer on May 25, 2026 at 9:39 pm
    while (counter <= 4){
        var t=setTimeout("changeImage(bannerList[counter])", 5000);
        counter = counter + 1;
    
        if (counter > 4){
            counter = 0;
        }
    }
    

    that, my friend, is an infinite loop and is always suspect… it will never reach 5. the reason why it crashes (at least for me) is because it doesn’t wait for the timeout to end before it loops again. You might consider using something like this:

    Also, you can’t pass parameters as a string (e.g. the “changeImage(bannerList[counter])”). You need to concatenate like so:

    var t=setTimeout("changeImage('"+bannerList[counter]+"')", 1000);
    

    Then to actually make it loop, you want to put another call to the timeout inside the changeImage function (so it does it after the time and not all five at the same time). This will mean that both counter and bannerList need to be global. Then with a little js monkey business you get the following version:

    var counter = 0;
    var bannerList = new Array();
    
    function bannerRotator(){
        bannerList[0] = "portfolio/1.jpg"
        bannerList[1] = "portfolio/2.jpg"
        bannerList[2] = "portfolio/3.jpg"
        bannerList[3] = "portfolio/4.jpg"
        bannerList[4] = "portfolio/5.jpg"
    
    
        var t=setTimeout("changeImage('"+bannerList[counter]+"')", 1000);
    
    }
    function changeImage(newImgLoc){
        document.getElementById("slide").src = newImgLoc;
        setTimeout("changeImage('"+bannerList[++counter%bannerList.length]+"')", 1000);
    }
    

    You can see a demo here: Demo

    if you want to actually see images changing, you’ll need to plug their absolute paths.

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

Sidebar

Related Questions

The following code is pretty self-explanatory and my question is very simple : Why
The following code works very well when all involved classes are in the same
I'm finding this kind of overriding after a new in java code very often
I am doing some self-learning about JQuery. Here is the code for my very
there's very strange error with my code.. In fact, there's no errors at all,
I am trying to run a very simple server/client ssl code with a self
Maybe the title of the question is not very self-explanatory but I don't know
I have a piece of code VERY similar to this one http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching I the
Currently, each td../td prints in just 1 line which makes the source code very
The below code is very simple. I have a jQuery autocomplete bound to an

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.