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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:16:24+00:00 2026-06-08T12:16:24+00:00

I have a section of code in my $(document).ready(function() {} that reads: getInitial(len); Where

  • 0

I have a section of code in my $(document).ready(function() {} that reads:
getInitial(len);
Where len is an integer.

function getInitial(number){
    number--;
    if(number < 0) return
    var $items = $(balls()); 
    $items.imagesLoaded(function(){
        $container
        .masonry('reloadItems')
        .append( $items ).masonry( 'appended', $items, true );
    });
    getInitial(number);
}

Notice the line that reads: var $items = $balls(());

That is defined as:

function balls(){
    $iterator -= 1;
    if($iterator < 0){
        var $boxes = $( '<div class="box">No more games!</div>' );
        $container.append( $boxes ).masonry( 'appended', $boxes, false );   
        return; 
    }
    var imgPreload = new Image();
    var ret; 
    imgPreload.src = 'scripts/php/timthumb.php?src='+$test[$iterator][2]+'&q=100&w=300';
    $(".imgHolder").append('<img src="'+imgPreload.src+'"/>');
    //console.log(imgPreload);
    $(".imgHolder").imagesLoaded(function(){
        ret = '<div class="box" style="width:18%;">'
            +'<p>'+$test[$iterator][1][2]['name']+'</p>'
            +'<img src="'+imgPreload.src+'"/>'//Replace this with the one below when timthumb is whitelisted
            +'<div id=boxBottom>'+Math.floor($test[$iterator][0]*100)+'%</div>'
            +'</div>';
    });
    console.log(ret);
    return ret;
}

My question is how can I get ret from the imagesLoaded() method inside of the balls() function to return to the $items inside of getInitial()?

I hope there’s no more confusion.

  • 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-08T12:16:25+00:00Added an answer on June 8, 2026 at 12:16 pm

    Since your function runs asynchronously, you need a callback function. You cannot have it return a value. Return values by passing callbacks.

    function getInitial(number){
        number--;
        if(number < 0) return
        // Can't do the following, it's asynchronous
        // var $items = $(balls()); 
    
        // Do this instead
        balls(function(html) {
            var $items = $(html);
            $items.imagesLoaded(function(){
                $container
                .masonry('reloadItems')
                .append( $items ).masonry( 'appended', $items, true );
            });
            getInitial(number);
        })
    }
    
    function balls(callback){
        $iterator -= 1;
        if($iterator < 0){
            var $boxes = $( '<div class="box">No more games!</div>' );
            $container.append( $boxes ).masonry( 'appended', $boxes, false );   
            return; 
        }
        var imgPreload = new Image();
        var ret; 
        imgPreload.src = 'scripts/php/timthumb.php?src='+$test[$iterator][2]+'&q=100&w=300';
        $(".imgHolder").append('<img src="'+imgPreload.src+'"/>');
        //console.log(imgPreload);
        $(".imgHolder").imagesLoaded(function(){
            callback('<div class="box" style="width:18%;">'
                +'<p>'+$test[$iterator][1][2]['name']+'</p>'
                +'<img src="'+imgPreload.src+'"/>'//Replace this with the one below when timthumb is whitelisted
                +'<div id=boxBottom>'+Math.floor($test[$iterator][0]*100)+'%</div>'
                +'</div>');
        });
    }
    

    Callbacks is how you return values from asynchronous functions

    There are probably still problems, the code is very confusing. But this should get you going in the right direction.

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

Sidebar

Related Questions

I have some code here: $(document).ready(function() { $(#querybox).live(keyup, function(e) { var code = (e.keyCode
I have the following code: <script> $(document).ready(function() { $('.toggle_section').click(function(e){ parent = $(e.target).closest(div) objChild =
I have the following code: $(document).ready(function(){ $(window).scroll(function(){ Topo = $(window).scrollTop(); ObjScrollASoda.css({ 'marginTop' : (Topo
I have a section of code which should be executed by a maximum number
I have a section of code that can be summarised as follows; void MyFunc()
I have the following section of code in an app that I am writing:
I have some VERY simple code to return the title for a section header:
I have setup the following jQuery UI Dialog within my document.ready() section, i.e: $(#dialog).dialog({
I have this view (DetailsContainer, first class in code section of this question) with
In my xaml code, inside the Window.Resources section, I have defined a Data Template

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.