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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:09:57+00:00 2026-05-10T19:09:57+00:00

I have read the post here about using setTimeout() during intensive DOM processing (using

  • 0

I have read the post here about using setTimeout() during intensive DOM processing (using JavaScript), but how can I integrate this function with the below code? The below code works fine for a small number of options, but when the number of options gets too big my ‘please wait’ animated GIF freezes while the local JavaScript is processing. Thanks!

function appendToSelect() {     $('#mySelect').children().remove() ;     $('#mySelect').html(         '<option selected value='' + obj.data[0].value + ''>'         + obj.data[0].name         + '</option>'     );     var j = 1 ;     for (var i = 1; i < obj.data.length; i++) {         $('#mySelect').append(             '<option value='' + obj.data[i].value + ''>'             + obj.data[i].name             + '</option>'         );      } } 
  • 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. 2026-05-10T19:09:58+00:00Added an answer on May 10, 2026 at 7:09 pm

    Here is a solution:

    function appendToSelect() {   $('#mySelect').children().remove();   $('#mySelect').html(     '<option selected value=''+obj.data[0].value+''>'     + obj.data[0].name     + '</option>'   );   obj.data.splice(0, 1); // we only want remaining data   var appendOptions = function() {     var dataChunk = obj.data.splice(0, 10); // configure this last number (the size of the 'chunk') to suit your needs     for(var i = 0; i < dataChunk.length; i++) {       $('#mySelect').append(         '<option value='' + dataChunk[i].value + ''>'         + dataChunk[i].name         + '</option>'       );     }     if(obj.data.length > 0) {       setTimeout(appendOptions, 100); // change time to suit needs     }   };   appendOptions(); // kicks it off } 

    Not as elegant as @Borgar’s solution, but you get the idea. Basically, I am doing the same thing, but all in your one function rather than breaking it into a higher-order function like he does. I like his solution, but if you don’t, perhaps this will work for you.


    EDIT: For those that don’t immediately see it, one of the main differences between this solution and @Borgar’s is that this solution allows you to set the size of the ‘chunks’ of data that is processed between each timeout. @Borgar’s times-out after every single member of the array is processed. If I get time, I will try to create a higher-order function to handle this so it is more elegant. No promises though! 😉


    EDIT: So, here is my adaptation of @Borgar’s solution, which allows for setting a ‘chunk’ size and configuring the timeout value more easily:

    function incrementallyProcess(workerCallback, data, chunkSize, timeout, completionCallback) {   var itemIndex = 0;   (function() {     var remainingDataLength = (data.length - itemIndex);     var currentChunkSize = (remainingDataLength >= chunkSize) ? chunkSize : remainingDataLength;     if(itemIndex < data.length) {       while(currentChunkSize--) {         workerCallback(data[itemIndex++]);       }       setTimeout(arguments.callee, timeout);     } else if(completionCallback) {       completionCallback();     }   })(); }  function appendToSelect() {   $('#mySelect').children().remove();   $('#mySelect').html(     '<option selected value='' + obj.data[0].value + ''>'     + obj.data[0].name     + '</option>'   );   obj.data.splice(0,1); // we only want remaining data         incrementallyProcess(function(data) {     $('#mySelect').append(     '<option value='' + data.value + ''>'     + data.name     + '</option>'    );   }, obj.data, 10, 100, removeAnimatedGifFunction); // last function not required... } 

    Hope that helps – I think this combines the best of both solutions. Notice, the second anonymous function no longer uses the index value, but simply passes in the entire object (with the value and name properties); that makes it a bit cleaner, since the index of the current object really isn’t usually that useful when iterating over things, IMO.

    I am sure there are still things that could be done to make this even better, but that is left as an exercise for the reader. 😉

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A quick 'n dirty way to get the actual heap… May 11, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer What you are looking for is a reverse proxy and… May 11, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer According to this post, the 'Notes' data isn't accessible via… May 11, 2026 at 11:56 pm

Related Questions

I have noticed that cURL in PHP returns different data when told to output
I have a method that creates a MessageDigest (a hash) from a file, and
I've successfully been able to make elements (like div's, panel's, whatever) draggable by using
I am trying to numerically integrate an arbitrary (known when I code) function in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.