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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:21:35+00:00 2026-06-19T04:21:35+00:00

I am trying to create a simple slideshow consisting of 3 rotating images that

  • 0

I am trying to create a simple slideshow consisting of 3 rotating images that will start over as soon as the last has displayed, timed 5000ms apart.

<div id="slideshow">&nbsp;</div>

<script type="text/javascript">
var imageArray = ['Image1','Image2','Image3'];
var currentIndex = 0;

nextPic = function(currentIndex,slideshow) {

  var theHTML = '<img src="http://www.domain.com/Pics/Test-' + imageArray[currentIndex] + '.jpg">';
  document.getElementById("slideshow").innerHTML = theHTML;

  if (currentIndex < imageArray.length) {
      currentIndex = currentIndex + 1;
  }
    else {
      currentIndex = 0;
    }

  setTimeout("nextPic(" + currentIndex + ")", 5000);
}

nextPic(currentIndex, "slideshow");

</script>

Every variation of Javascript code I have found has produced the same result: after the last image (Test-Image3.jpg), the JS attempts to display an undefined image (“Test-undefined.jpg”) before resetting back to the first one. It works perfectly fine other than that and it’s quite maddening.

  • 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-06-19T04:21:37+00:00Added an answer on June 19, 2026 at 4:21 am

    You need to take into account the fact that you’re adding one after checking against the length of the array:

    if (currentIndex < imageArray.length - 1) {
      currentIndex = currentIndex + 1;
    }
    else {
      currentIndex = 0;
    }
    

    or

    currentIndex += 1;
    if (currentIndex >= imageArray.length)
      currentIndex = 0;
    

    You really don’t need to pass the parameter at all, however, because the function can just use the global variable. (It’d be better not to have one, but since you do, well, you might as well use it.)

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

Sidebar

Related Questions

I am trying to create a simple image slideshow that fades in and out
I'm trying to create simple slideshow where if I click the image it will
I'm trying to create simple function that will work two ways. Basically, when I
I'm trying to create a simple jQuery slideshow that doesn't load all of the
I'm trying to create simple script that subscribes a user to a company calendar.
I am trying to create a simple about page that uses JQuery click to
I'm trying to create a simple web page that resembles the following: I've got
I am trying to create a simple image slideshow type thing with the Javascript
I am trying to create simple CRUD application. I have a partial view that
Trying to create a simple custom control in C# Winforms that inherits from Panel,

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.