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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:04+00:00 2026-05-30T12:16:04+00:00

I have a little problem with a homemade script, first I’ll give you the

  • 0

I have a little problem with a homemade script, first I’ll give you the script

    var heighti = $(window).height();
var imageLoading = new Array();
$('.fullHeight').css({'height' : heighti});
    var now,hour,minute,second,dateNow = new Array(),countImg=0,i=0,countDateNow = 0;countImg=0,countThis=0,countDateNowAj=0;
        /* GET THIS HOUR */
        now = new Date();
        hour      = now.getHours();
        minute    = now.getMinutes();
        second    = now.getSeconds();
    function date(){
        //Function to get date
}
function loadImage(){
    countThis = 0;
    while(countThis < 6){
    date();
    var imgOn = 'uploads/original/'+dateNow[countDateNowAj]+'.jpg';
    console.log(imgOn);
    var img = $("<img />").attr('src', imgOn)
                  .load(function(){
                    imageLoading[i] = imgOn ;
                    i++;
                  })
                  .error(function(){
                  console.log('This is the image now : '+imgOn);
                    imageLoading[i] = 'images/noimage.jpg';
                    i++;
                  });
        countThis++;
        countDateNowAj++;
    }
}


setInterval("dateImg()",1000);
setTimeout("loadImage()",0);
setInterval("loadImage()",5000);

So this is my function, everything works but when I want to do imageLoading[i] = imgOn; the script take always the last value.

This is a log of what I’m talking about : http://minus.com/mpWvBsXkQ

First I check the time
After I check the image who is gonna be checked
And at the end I check the name of imageLoading[i] = imgOn;

And I always get the last time and not every second.

I hope you’ll understand my query.

  • 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-30T12:16:05+00:00Added an answer on May 30, 2026 at 12:16 pm

    In the load and error handler functions, you are using variables from the outer scope (in this case the scope will be the loadImage function) asynchronously, but they will be changed synchronously as part of the loop. If you want to have them held constant until the handlers are actually called, you will need to use a closure:

    function loadImage(){
       function imageLoader(i, imgOn) {
          console.log(imgOn);
          var img = $("<img />").attr('src', imgOn)
             .load(function(){
                imageLoading[i] = imgOn ;
             })
             .error(function(){
                console.log('This is the image now : '+imgOn);
                imageLoading[i] = 'images/noimage.jpg';
             });
       }
    
       for(countThis = 0; countThis < 6; countThis++, countDateNowAj++) {
          date();
          imageLoader(i++, 'uploads/original/'+dateNow[countDateNowAj]+'.jpg');
       }
    }
    

    In this case, the imageLoader inner function becomes the scope that the load and error handlers run in, so the values of i and imgOn are as you would expect rather than always being the last values they had when the loop finished running.

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

Sidebar

Related Questions

I have a little problem with a simple vbScript. The script has to run
I have a little problem, I have an array and I want to add
I have little problem with printing data like this, I have written script like
I have a little problem with my script. When I try to run it
I have little problem with my script. Here is the code. http://pastie.org/2361140 When I
I have a little problem with converting a char string array to an unsigned
I have this little problem with json. //real json var json1 = {test1:TEST1,test2:TEST2,test3:TEST3,test4:TEST4}; alert(json.test1);
I have a little problem, I don't know how to create the script (with
I have a little problem with my function: function swear_filter($string){ $search = array( 'bad-word',
i have little problem with boost::asio library. My app receive and process data asynchronously,

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.