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

  • Home
  • SEARCH
  • 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 8515645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:12:21+00:00 2026-06-11T05:12:21+00:00

When I start the diashow this is what I get: Uncaught TypeError: Cannot read

  • 0

When I start the diashow this is what I get: Uncaught TypeError: Cannot read property 'src' of undefined Pointing to function: runPicGal (see below). Hope you can help. Note: The strange thing is that I see the picture changing ONE time then I get the error.

Full JS File:

var picForDiashow;
var diashowPicArray = [];
var diashowPicArrayIndex = 0;

diashowPicArray [0] = new Image(); diashowPicArray [0].src = "./pics/1.jpg";
diashowPicArray [1] = new Image(); diashowPicArray [0].src = "./pics/2.jpg";
diashowPicArray [2] = new Image(); diashowPicArray [0].src = "./pics/3.jpg";
diashowPicArray [3] = new Image(); diashowPicArray [0].src = "./pics/4.jpg";
diashowPicArray [4] = new Image(); diashowPicArray [0].src = "./pics/5.jpg";



function initForDiashow () {

    picForDiashow = document.getElementById("diashowPic");
}

window.onload = initForDiashow;





function startDiashow () {

    picInterval = window.setInterval(runPicGal, 1000);
}





function stopDiashow () {

    window.clearInterval(picInterval);
}




function runPicGal () {

    diashowPicArrayIndex++;

    if (diashowPicArrayIndex > diashowPicArray.length) {
        diashowPicArrayIndex = 0;
    } 
    picForDiashow.src = diashowPicArray[diashowPicArrayIndex].src;

}
  • 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-11T05:12:22+00:00Added an answer on June 11, 2026 at 5:12 am

    You are always adding the elements to the first position of the array. Thus, only the first element, diashowPicArray[0], will be accessible. Change the initialization to the following:

    diashowPicArray [0] = new Image(); diashowPicArray [0].src = "./pics/1.jpg";
    diashowPicArray [1] = new Image(); diashowPicArray [1].src = "./pics/2.jpg";
    diashowPicArray [2] = new Image(); diashowPicArray [2].src = "./pics/3.jpg";
    diashowPicArray [3] = new Image(); diashowPicArray [3].src = "./pics/4.jpg";
    diashowPicArray [4] = new Image(); diashowPicArray [4].src = "./pics/5.jpg";
    

    Also, in your comparison, you should not use diashowPicArrayIndex > diashowPicArray.length. Otherwise, you’ll try to access diashowPicArray[5], which is out of bounds. Use == instead:

    diashowPicArrayIndex++;
    if (diashowPicArrayIndex == diashowPicArray.length) {
        diashowPicArrayIndex = 0;
    } 
    

    Or, simplifying the above lines, using modular arithmetic:

    diashowPicArrayIndex = (diashowPicArrayIndex + 1) % diashowPicArray.length;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I start a download using PHP with this code: <? $_REQUEST['file'] = urldecode($_GET['file']); header(Content-type:
I start with SQLAlchemy and i try to get my last insert (a Tweet)
to start with I have this: <body class=nojs> I'm trying to remove the nojs
I start to read JavaScript Patterns , some codes confused me. var global =
Today start using the new version of Netbeans 7.1.2, I get the below notice
long start = System.currentTimeMillis(); URL link = (any url); BufferedReader read = new BufferedReader(new
To start: This is also for REST deserialiaztion, so a custom XmlSerializer is out
Start with this: [G|C] * [T] * Write a program that generates this: Cat
start date: 2012-05-29 08:30:00.000 end date: 2012-05-29 15:00:00.000 DATEDIFF(hour,StartDateTime,EndDateTime) This gives me 7 hours,
I start a tornado http server like this: app = tornado.web.Application([ (r'.*', MyRequestHandler), ])

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.