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

  • Home
  • SEARCH
  • 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 7894375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:22:48+00:00 2026-06-03T07:22:48+00:00

Is there a way to check if a function has completed its operation using

  • 0

Is there a way to check if a function has completed its operation using either javascript or jquery?

I’m trying to make a counter that slows down as the number gets bigger(decelerating the output, if you will), using setTimeout. As you know, the larger the number the longer the delay (in setTimeout).

What I’m trying to do is click a button, then current loop iteration is printed on the screen. This loop number is used as the setTimeout delay, so while the number is low it will quickly rush through, as it gets bigger the delay is larger thus making it print the number more slowly (since this number is the delay and the larger the delay the less often it prints it).

Here is the logic I'm trying to accomplish
1. Click button
2. Initiate loop
3. trigger function to set timeout
4. set timeout triggers a function to print the loop iteration #
5. Repeat step 3 until the number of set iterations is completed

Well, as you can see when the timeout is set the loop will continue, but there will be a timeout delay. Is there any way that I can put a pause-type function that waits until the timeout function is completed, and then continue onto the next iteration?

Here is my code

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
</head>

<body>
<form>
<input type="button" value="Display alert box"
onclick="setMessage()" />

<script>

 function setMessage(){
 for(i=0;i<5000;i++){
 var b = i;
 timeMsg();
//some sort of puase here checking until timeMsg & docWrite are completed, then continue to the next iteration
    }
}

function timeMsg(){
var t=setTimeout("docWrite()",b);
}   


function docWrite(){
document.write(i);
}
</script>
</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-03T07:22:50+00:00Added an answer on June 3, 2026 at 7:22 am

    Instead of doing this in a for loop, I would recommend doing something like the following:

    function docWrite(i){
        document.write(i);
    }
    
    function timeMsg(counter) {
      var t;
    
      counter++;
      if (counter < 5000) {
        t = setTimeout(function(counter){ 
          docWrite(counter);
          timeMsg(counter);
        }, counter, counter)    
      }
    }
    
    timeMsg(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to check if a ValidationSummary control has its IsValid property
Using the keyup on jQuery, is there a way to check a what textfield
Is there any way to check whether a file is locked without using a
Is there a way to check if a file has been opened by ReWrite
In .NET, is there a simple way to check whether the current user has
Is there any way to check if an included document via include('to_include.php') has returned
Is there a way to check if an object has any fields? For example,
Is there any way to check/manage the push notifications (C2DM or from other service)
Is there a way to check to see if a date/time is valid you
Is there any way to check if a given index of an array exists?

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.