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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:30:10+00:00 2026-05-25T11:30:10+00:00

I have many countdown timers on the page. Timers countdown remaining time from current

  • 0

I have many countdown timers on the page. Timers countdown remaining time from current time to time in future.

I need to have current timer value seperate from html, because element on page may change (appear/disappear) cause filtering/sorting scripts.

My naive implementation just hangs out the browser:

var CountdownTimer = function(id, endTime) {    
    this.id = id;
    this.endTime = endTime;
    this.remainingSeconds = parseInt((this.endTime - CountdownTimer.startTime) / 1000);
};
CountdownTimer.prototype.start = function() {
    while (this.remainingSeconds > 0) {
        setTimeout('this.tick()', 1000);
    }
};

CountdownTimer.prototype.tick = function() {
    this.remainingSeconds--;
    console.log(this.id + ': ' + this.remainingSeconds);
};

CountdownTimer.startTime = new Date().getTime();

$(document).ready(function() {  
    var endTimes = Drupal.settings.snuper_filter.end_times,
        activeTimers = [];

    for(var i = 0; i < endTimes.length; i++) {
        activeTimers.push(new CountdownTimer(endTimes[i].nid, endTimes[i].endTime));
    }
    endTimes = Drupal.settings.snuper_filter.end_times = null;

    for (var i = 0; i < activeTimers.length; i ++) {
        activeTimers[i].start();        
    }

});

Could somebody give me some advice how to handle this?

  • 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-25T11:30:11+00:00Added an answer on May 25, 2026 at 11:30 am

    You’re continuously setting timeouts in your while loop. Just set one timeout in start and set timeouts in the tick function (you need to set self to this):

    CountdownTimer.prototype.start = function() {
        var self = this;
        setTimeout(function() {self.tick()}, 1000);
    };
    
    CountdownTimer.prototype.tick = function() {
        this.remainingSeconds--;
        console.log(this.id + ': ' + this.remainingSeconds);
        if(this.remainingSeconds > 0) {
            var self = this;
            setTimeout(function() {self.tick()}, 1000);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many lines on my page generated from database with PHP. Each line
I have many emails coming in from different sources. they all have attachments, many
I have many directories with some phrase (domain name) in its name. Need to
I have many links in a HTML-table, which delete corresponding row, when clicked (calling
I have many SWF file those I have included in my web page using
I have many textboxes that need to be enabled only when certain action are
I have many methods that need the previous one to complete before firing the
I have many years of experience in Java including Swing, Servlet and JDBC, but
I have many items inside a list control. I want each item to have
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,

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.