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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:36:03+00:00 2026-06-17T01:36:03+00:00

I try to change a label’s text periodically by using the following code: function

  • 0

I try to change a label’s text periodically by using the following code:

    function sleep(milliSeconds) {
        var startTime = new Date().getTime();
        while (new Date().getTime() < startTime + milliSeconds); 
    }
    function showMap() {
        var str = document.getElementById("lbPoints").firstChild.nodeValue;
        var lbl = document.getElementById("my");
        var strs = str.split("-");
        var millisecondsToWait = 500;

        for (var i = 0; i < strs.length-1; i++) {
            lbl.innerHTML = strs[i];
            sleep(500);
        }     
    }

My “str” and “strs” are right. Code works, but as waits for 5 seconds and print the final string in strs to screen and nothing else. What can I do to change it periodically?

  • 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-17T01:36:04+00:00Added an answer on June 17, 2026 at 1:36 am

    That’s not how you sleep. In no language is it correct to test repeatedly
    until a date.

    Do this instead :

    function showMap() {
        var str = document.getElementById("lbPoints").firstChild.nodeValue;
        var lbl = document.getElementById("my");
        var strs = str.split("-");
        var millisecondsToWait = 500;
        var i=0;
        var interval = setInterval(function(){
            if (i==strs.length-2) clearInterval(interval); 
            lbl.innerHTML = strs[i++];
        }, millisecondsToWait);   
    }
    

    Demonstration

    This uses setInterval to call repeatedly a function, and clearInterval at the end of array to stop the function being called.

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

Sidebar

Related Questions

I am trying to label Y-axis of my graph using following code: svg1.append(text).attr(class, y
I try to change a string into an object using eval but failed. var
I have an asp.net label web control. I change its text dynamically using jQuery
When I try to change the default collation of a SQL Server instance using
I'm try to change text color and align item in spinner to center of
I'm try to change the text on a JLabel when the Jbutton is clicked
I'm attempting to change the text of a label in a piece of C#
I try to change the backgroundcolor of a label, by clicking on a button.
I have problem with c# script who change user AD password, when try change
I try to change the color from a UIPopoverControler on iOS 5. To do

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.