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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:39:38+00:00 2026-05-15T00:39:38+00:00

I have this countdown script wrapped as an object located in a separate file

  • 0

I have this countdown script wrapped as an object located in a separate file

Then when I want to setup a counter, the timeout function in the countdown class can not find the object again that I have setup within the document ready.

I sort of get that everything that is setup in the document ready is convined to that scope,
however it is possible to call functions within other document ready´s.

Does anyone has a solution on how I could setup multiple counters slash objects.
Or do those basic javascript classes have to become plugins

This is the class

  function countdown(obj)
{
    this.obj        = obj;
    this.Div        = "clock";
    this.BackColor      = "white";
    this.ForeColor      = "black";
    this.TargetDate     = "12/31/2020 5:00 AM";
    this.DisplayFormat  = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    this.CountActive    = true;

    this.DisplayStr;

    this.Calcage        = cd_Calcage;
    this.CountBack      = cd_CountBack;
    this.Setup      = cd_Setup;
}

function cd_Calcage(secs, num1, num2)
{
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2) s = "0" + s;
  return (s);
}
function cd_CountBack(secs)
{
  this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g,    this.Calcage(secs,86400,100000));
  this.DisplayStr = this.DisplayStr.replace(/%%H%%/g,       this.Calcage(secs,3600,24));
  this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,       this.Calcage(secs,60,60));
  this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,       this.Calcage(secs,1,60));

  //document.getElementById(this.Div).innerHTML = this.DisplayStr;

  $('#'+this.Div).text(this.DisplayStr);
  $('#tel').text(parseInt( $('#tel').text() )+1);


  if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
}
function cd_Setup()
{
    var dthen   = new Date(this.TargetDate);
    var dnow    = new Date();
    ddiff       = new Date(dthen-dnow);
    gsecs       = Math.floor(ddiff.valueOf()/1000);
    this.CountBack(gsecs);
}

and setting it up

$(document).ready(function() { 
  var cd1 = new countdown('cd1');
  cd1.Div = "clk";
 cd1.TargetDate = "08/15/2010 8:00 PM";
  cd1.DisplayFormat = "%%D%% days, %%H%% hours, %%M%% minutes, %%S%% seconds until event   AAA happens"; 
 cd1.Setup(); 

firebug says it errors out with the timeout function

thanks, Richard

  • 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-15T00:39:39+00:00Added an answer on May 15, 2026 at 12:39 am

    cd1 is defined in the local scope. setTimeout will run the function passed as parameter 1 in the window [global] scope, and in your case, window.cd1 is undefined.

    The solution for your problem would to make cd1 a global variable. [Remove the “var” in your declaration of cd1]


    Off topic: I recommend you look into using anonymous functions, as they can make your code much more pretty/legible at times.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Spatial extensions to relational database systems provide storage and indexed… May 15, 2026 at 4:12 am
  • Editorial Team
    Editorial Team added an answer You can serialize to a ByteArrayOuputStream. Just pass one to… May 15, 2026 at 4:12 am
  • Editorial Team
    Editorial Team added an answer Nope, You also have to give the either class name… May 15, 2026 at 4:12 am

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.