www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Rate Thread Display Modes
      #1  
    Old 02-08-2010, 03:44 PM
    sandy312 sandy312 is offline
    Registered User
     
    Join Date: Mar 2008
    Posts: 3
    Timer counter

    I am trying to implement a modified countdown timer from

    Author: Robert Hashemian
    http://www.hashemian.com/

    But, I get error. Can someone help me in pointing out what the error is.

    Code:
    <html>
    <head>
    <script language="JavaScript">
    
    TargetDate = "02/08/2010 5:00 PM UTC-0500";
    DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    CountStepper = -1;
    LeadingZero = true;
    FinishMessage = "It is finally here!";
    
    function calcage(secs, num1, num2) {
      s = ((Math.floor(secs/num1))%num2).toString();
      if (LeadingZero && s.length < 2)
        s = "0" + s;
      return "<b>" + s + "</b>";
    }
    
    function CountBack(secs) {
      if (secs < 0) {
        document.getElementById('countbox').innerHTML = FinishMessage;
        return;
      }
      DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
      DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
      DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
      DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));
    
      document.getElementById('countbox').innerHTML = DisplayStr;
      if (CountActive)
        setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
    }
    
    if (CountStepper == 0)
      CountActive = false;
      
    if (CountStepper == 0)
      CountActive = false;
    var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
    var dthen = new Date(TargetDate);
    var dnow = new Date();
    if(CountStepper>0)
      ddiff = new Date(dnow-dthen);
    else
      ddiff = new Date(dthen-dnow);
    gsecs = Math.floor(ddiff.valueOf()/1000);
    
    CountBack(gsecs);
    </script>
    </head>
    <body>
    <div id="countbox"></div>
    </body>
    </html>
    Orginal post from
    Author: Robert Hashemian
    http://www.hashemian.com/
    Reply With Quote
      #2  
    Old 02-08-2010, 06:53 PM
    justinbarneskin justinbarneskin is offline
    Registered User
     
    Join Date: Oct 2006
    Posts: 889
    HTML Code:
    <html>
    <head>
    <script language="JavaScript">
    
    TargetDate = "02/09/2010 5:00 PM UTC-0500";
    DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    CountStepper = -1;
    LeadingZero = true;
    FinishMessage = "It is finally here!";
    
    function calcage(secs, num1, num2) {
      s = ((Math.floor(secs/num1))%num2).toString();
      if (LeadingZero && s.length < 2)
        s = "0" + s;
      return "<b>" + s + "</b>";
    }
    
    function CountBack(secs) {
      if (secs < 0) {
        document.getElementById('countbox').innerHTML = FinishMessage;
        return;
      }
      DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
      DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
      DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
      DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));
    
      document.getElementById('countbox').innerHTML = DisplayStr;
      if (CountActive)
        setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
    }
    var CountActive=1;
    if (CountStepper == 0)
      CountActive = false;
      
    if (CountStepper == 0)
      CountActive = false;
    var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
    var dthen = new Date(TargetDate);
    var dnow = new Date();
    if(CountStepper>0)
      ddiff = new Date(dnow-dthen);
    else
      ddiff = new Date(dthen-dnow);
    gsecs = Math.floor(ddiff.valueOf()/1000);
    
    
    </script>
    </head>
    <body onload="CountBack(gsecs)">
    <div id="countbox"></div>
    </body>
    </html>

    Last edited by justinbarneskin; 02-08-2010 at 06:57 PM. Reason: var CountActive=1;
    Reply With Quote
      #3  
    Old 02-09-2010, 02:05 PM
    sandy312 sandy312 is offline
    Registered User
     
    Join Date: Mar 2008
    Posts: 3
    Smile Thank you. That really helped

    A small fix solved a very big problem... Thank you.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:13 PM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.