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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:43:36+00:00 2026-06-11T14:43:36+00:00

The problem about new Image() The following code is from ‘JavaScript by Example Second

  • 0

The problem about new Image()

The following code is from ‘JavaScript by Example Second Edition’, I think

planet[0] = "images/Venus.jpg" 

is wrong, It should be

planet[0].src = "images/Venus.jpg" 

and replace

document.images["planet_pic"].src = planet[i]; 

with

document.images["planet_pic"].src = planet[i].src;

Is it right?

<!DOCTYPE html>
<html>
<head>
    <title>Slide Show</title>
    <script type="text/javascript">
        var i = 0;
        var timeout;
        function preLoadImages() {
            if (document.images) {
                planet = new Array(); // global variable
                planet[0] = new Image();
                planet[0] = "images/Venus.jpg";
                planet[1] = new Image();
                planet[1] = "images/Neptune.jpg";
                planet[2] = new Image();
                planet[2] = "images/Earth.jpg";
                planet[3] = new Image();
                planet[3] = "images/Mars.jpg";
                planet[4] = new Image();
                planet[4] = "images/Jupiter.jpg";
            }
            else {
                alert("There are no images to preload");
            }
        }
        function startSlideShow() {
            if (i < planet.length) {
                document.images["planet_pic"].src = planet[i];
                i++;
            }
            else {
                i = 0;
                document.images["planet_pic"].src = planet[i];
            }
            timeout = setTimeout('startSlideShow()', 1500);
        }
        function stopSlideShow() {
            clearTimeout(timeout);
        }
    </script>
</head>
<body bgcolor="black" onload="preLoadImages()">
    <img name="planet_pic" src="/images/Jupiter.jpg" height="348"
        width="545px" />
    <form>
        <br />
        <br />
        <input type="button" value="Start Show"
            onclick="return startSlideShow();" />
        <input type="button" value="Stop Show"
            onclick="return stopSlideShow();" />
    </form>
</body>
</html>
  • 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-11T14:43:38+00:00Added an answer on June 11, 2026 at 2:43 pm

    Yes, it should be,

    planet[0] = new Image();
    planet[0].src = "images/Venus.jpg";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code transfers an image that is created on the fly from a
i'm new to c++ and having a little problem understanding about c++'s casting. According
Just curious. I heard something about the new G1GC addressing that latency problem. I
I'm new to SVN and I'm quite confused about a problem. I am using
I am having problem saving additional information about each user automatically when a new
I'm having problems implementing an asynchronous image loader to the following code. I read
I'm trying to understand what it is about the following code that is perfectly
I'm following the example on the android tutorial about the GridView, but instead of
I am using the following piece of code to load images as thumbnails to
I am relatively new to rails and think that my problem may, in part,

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.