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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:58:07+00:00 2026-05-23T15:58:07+00:00

When I try to run the code below the browser does not display an

  • 0

When I try to run the code below the browser does not display an image, instead it displays: [object HTMLImageElement].

I want to create a clock that shows a different picture for every minute (thing for the wife). I started by making a function that finds the date from the browser’s clock, turns it into string value which will be the file name. The function is called when the webpage loads and the function is updated every second. There is a tag with a tag id call, where the final result should be displayed.

All my pictures are stored in a file called images
The photos are numbered from 0000.jpg to 2359.jpg (to match the time of day)

I can not figure out what I am doing wrong. I tried my best to comment each line of the code so maybe that will help out in any answers.

<html>
<head>
<script language="javascript" type="text/javascript">

//function to get and update the picture file based on the user's clock
function updatePicture ()
{

//variable for getting the date on the user's clock
var clockTime = new Date ();

//variables for showing just the hours and minutes
var hours = clockTime.getHours();
var minutes = clockTime.getMinutes();

//add leading zeros to hours and minutes under 10
hours = ( hours < 10 ? "0" : "" ) + hours;
minutes = ( minutes < 10 ? "0" : "" ) + minutes;

//turn hours and minutes into string values
var hoursString = hours.toString();
var minutesString = minutes.toString();

//variable puts hours and minutes strings together to make a picture file name
var timeToPictureFile = hoursString + minutesString;

//variable to make a new image object
var pictureFile = new Image;

//adding <img> tag and.jpg with timeToPictureFile to make the file name and url call
pictureFile.src = '<img src="images/' + timeToPictureFile + '.jpg"/>';

//update the time display
document.getElementById('picture').firstChild.nodeValue = pictureFile;
}
</script>
</head>

<!-- load the picture and update the picture every second -->
<body onLoad="updatePicture(); setInterval('updatePicture()',1000)">

<!-- a div to hold the picture -->
<div>
<span id="picture">&nbsp;</span>
</div>

</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-05-23T15:58:08+00:00Added an answer on May 23, 2026 at 3:58 pm

    My suggestion

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    //function to get and update the picture file based on the user's clock
    var oldImage = "";
    function updatePicture () {
      //variable for getting the date on the user's clock
      var clockTime = new Date();
      //variables for showing just the hours and minutes
      var hours = clockTime.getHours();
      var minutes = clockTime.getMinutes();
      //add leading zeros to hours and minutes under 10
      hours = ( hours < 10 ? "0" : "" ) + hours;
      minutes = ( minutes < 10 ? "0" : "" ) + minutes;
      //variable puts hours and minutes strings together to make a picture file name
      var timeToPictureFile = ""+hours + minutes +'.jpg';
    
      if (oldImage === timeToPictureFile) return; // no need to do this yet
      oldImage = timeToPictureFile; // save     
      //variable to make a new image object
      var pictureFile = new Image();
      pictureFile.src = timeToPictureFile; // preload the image;
      //update the time display - 
      // this could also be done changing an existing image's src attribute
      document.getElementById('picture').innerHTML = '<img src="'+pictureFile.src+'" />';
    }
    
    window.onload=function() {
      updatePicture(); 
      setInterval(updatePicture,1000); // check every second
    }  
    </script>
    </head>
    
    
    <body>
    <div>
    <span id="picture">&nbsp;</span>
    </div>
    
    </body>
    </html>
    

    OR

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    //function to get and update the picture file based on the user's clock
    function updatePicture () {
      //variable for getting the date on the user's clock
      var clockTime = new Date();
      //variables for showing just the hours and minutes
      var hours = clockTime.getHours();
      var minutes = clockTime.getMinutes();
      //add leading zeros to hours and minutes under 10
      hours = ( hours < 10 ? "0" : "" ) + hours;
      minutes = ( minutes < 10 ? "0" : "" ) + minutes;
      //variable puts hours and minutes strings together to make a picture file name
      var timeToPictureFile = ""+hours + minutes +'.jpg';
      //update the time display
      document.getElementById('picture').innerHTML = '<img src="'+timeToPictureFile+'" />';
    }
    
    window.onload=function() {
      updatePicture(); 
      setInterval(updatePicture,60000); // check every minute
    }  
    </script>
    </head>
    
    
    <body>
    <div>
    <span id="picture">&nbsp;</span>
    </div>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#exceptions is a html table. I try to run the code below, but it
I'm getting this error in ElementTree when I try to run the code below:
When I try to run the following code (from the REPL) in Clojure: (dotimes
I get a 500 internal server error when I try to run the code
For some reason, the code below fails on the second line with run-time error
When I try to run a .NET assembly ( boo.exe ) from a network
Every time I try to run a small application that uses a Derby DB
When I try to run a particular stored procedure on my MS SQL 2005
whenever I try to run something in Java, Eclipse changes into the PHP perspective.
I get a generic failure when I try to run: saslpasswd2 username This was

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.