www.webdeveloper.com
Results 1 to 7 of 7

Thread: Help Please Editing This Javascript Countdown Timer

  1. #1
    Join Date
    Jun 2014
    Posts
    3

    Lightbulb Help Please Editing This Javascript Countdown Timer

    I am using the countdown timer script from http://www.hashemian.com/tools/javascript-countdown.htm

    Code:
    <script language="JavaScript">
    TargetDate = "12/31/2020 5:00 AM";
    BackColor = "palegreen";
    ForeColor = "navy";
    CountActive = true;
    CountStepper = -1;
    LeadingZero = true;
    DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    FinishMessage = "It is finally here!";
    </script>
    <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
    The countdown is based on the client browser. How can I get the timer to reset every 2 hours, instead of every 24 hours?

    Thanks

  2. #2
    Join Date
    Jun 2014
    Location
    Cairns - Australia
    Posts
    81
    Anyone correct me if Im wrong.. Webtoseo, Its not all done client side...

    Half the script is here....

    <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
    Clearly "hashemian" have made it that way.. and its the "countdown.js" file you would probably have to tweak..


    Im sure you could find a complete script around the net somewhere... luck

  3. #3
    Join Date
    Jun 2014
    Location
    Cairns - Australia
    Posts
    81
    Crap.. I cant edit?... better put, it is client side but half the script is retrieved from hashemian's... its that you need to edit...

  4. #4
    Join Date
    May 2014
    Posts
    4
    Yes the script is retrieved from hashemian's

  5. #5
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,689
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <div id="count1" ></div>
    <input type="button" name="" value="Start" onclick="zxcCountDown.Start('count1');"/>
    <input type="button" name="" value="Stop" onclick="zxcCountDown.Stop('count1');"/>
    <input type="button" name="" value="Re Start 3 hours" onclick="zxcCountDown.Start('count1','0:0:3',true);"/>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var zxcCountDown={
    
     Start:function(id,t,srt){
      var o=this['zxc'+id],s
      if (o){
       s=this.sec(o,t);
       o.s=s>0?s:o.s;
       srt===true?o.d=new Date():null;
       this.tick(o);
      }
     },
    
     Stop:function(id){
      var o=this['zxc'+id]
      o?clearTimeout(o.to):null;
     },
    
     init:function(o){
      var id=o.ID,t=o.Time,p=document.getElementById(id),t=typeof(t)=='string'?t:'0,0,0',t=t.split(/\D/)
      if (p){
       o.s=0;
       o.p=p;
       this['zxc'+id]=o;
       o.d=new Date();
       o.Start!==false?this.Start(id,o.Time,true):null;
      }
     },
    
     tick:function(o){
      clearTimeout(o.to);
      var s=o.s-Math.floor((new Date()-o.d)/1000),d=Math.floor(s/86400),h=Math.floor(s/3600)%24,m=Math.floor(s/60)%60,c=s%60
      o.p.innerHTML=(s>86400?((d>9?'':'0')+d)+' Days ':'')+(s>3600?((h>9?'':'0')+h)+' Hours ':'')+(s>60?((m>9?'':'0')+m)+' Minutes ':'')+(c>0?((c>9?'':'0')+c)+' Seconds ':'')
      if (s>=0){
       o.ss=s;
       o.to=setTimeout(function(){ zxcCountDown.tick(o); },1000);
      }
      else if (typeof(o.OnComplete)=='function'){
       o.OnComplete();
      }
     },
    
     sec:function(o,t){
      var t=typeof(t)=='string'?t:'0,0,0',t=t.split(/\D/);
      return Math.floor((t[3]&&isFinite(t[3]*1)?t[3]*86400:0)+(t[2]&&isFinite(t[2]*1)?t[2]*3600:0)+(t[1]&&isFinite(t[1]*1)?t[1]*60:0)+(t[0]&&isFinite(t[0]*1)?t[0]*1:0));
     }
    
    }
    
    
    zxcCountDown.init({
     ID:'count1',
     Time:'0:0:2:0',   //  seconds:minutes:hours:days
     Start:true,
     OnComplete:function(){
      alert('done');
     }
    });
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  6. #6
    Join Date
    Jun 2014
    Posts
    3

    Thumbs up

    Quote Originally Posted by vwphillips View Post
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <div id="count1" ></div>
    <input type="button" name="" value="Start" onclick="zxcCountDown.Start('count1');"/>
    <input type="button" name="" value="Stop" onclick="zxcCountDown.Stop('count1');"/>
    <input type="button" name="" value="Re Start 3 hours" onclick="zxcCountDown.Start('count1','0:0:3',true);"/>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var zxcCountDown={
    
     Start:function(id,t,srt){
      var o=this['zxc'+id],s
      if (o){
       s=this.sec(o,t);
       o.s=s>0?s:o.s;
       srt===true?o.d=new Date():null;
       this.tick(o);
      }
     },
    
     Stop:function(id){
      var o=this['zxc'+id]
      o?clearTimeout(o.to):null;
     },
    
     init:function(o){
      var id=o.ID,t=o.Time,p=document.getElementById(id),t=typeof(t)=='string'?t:'0,0,0',t=t.split(/\D/)
      if (p){
       o.s=0;
       o.p=p;
       this['zxc'+id]=o;
       o.d=new Date();
       o.Start!==false?this.Start(id,o.Time,true):null;
      }
     },
    
     tick:function(o){
      clearTimeout(o.to);
      var s=o.s-Math.floor((new Date()-o.d)/1000),d=Math.floor(s/86400),h=Math.floor(s/3600)%24,m=Math.floor(s/60)%60,c=s%60
      o.p.innerHTML=(s>86400?((d>9?'':'0')+d)+' Days ':'')+(s>3600?((h>9?'':'0')+h)+' Hours ':'')+(s>60?((m>9?'':'0')+m)+' Minutes ':'')+(c>0?((c>9?'':'0')+c)+' Seconds ':'')
      if (s>=0){
       o.ss=s;
       o.to=setTimeout(function(){ zxcCountDown.tick(o); },1000);
      }
      else if (typeof(o.OnComplete)=='function'){
       o.OnComplete();
      }
     },
    
     sec:function(o,t){
      var t=typeof(t)=='string'?t:'0,0,0',t=t.split(/\D/);
      return Math.floor((t[3]&&isFinite(t[3]*1)?t[3]*86400:0)+(t[2]&&isFinite(t[2]*1)?t[2]*3600:0)+(t[1]&&isFinite(t[1]*1)?t[1]*60:0)+(t[0]&&isFinite(t[0]*1)?t[0]*1:0));
     }
    
    }
    
    
    zxcCountDown.init({
     ID:'count1',
     Time:'0:0:2:0',   //  seconds:minutes:hours:days
     Start:true,
     OnComplete:function(){
      alert('done');
     }
    });
    /*]]>*/
    </script>
    </body>
    
    </html>
    This is a 2 hour countdown but it resets at every page load. the script will be used site wide. Can you make it countdown to a set time and reset on its own? Anyone? thanks a lot!

  7. #7
    Join Date
    Jun 2014
    Posts
    3

    Smile

    Quote Originally Posted by vwphillips View Post
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <div id="count1" ></div>
    <input type="button" name="" value="Start" onclick="zxcCountDown.Start('count1');"/>
    <input type="button" name="" value="Stop" onclick="zxcCountDown.Stop('count1');"/>
    <input type="button" name="" value="Re Start 3 hours" onclick="zxcCountDown.Start('count1','0:0:3',true);"/>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var zxcCountDown={
    
     Start:function(id,t,srt){
      var o=this['zxc'+id],s
      if (o){
       s=this.sec(o,t);
       o.s=s>0?s:o.s;
       srt===true?o.d=new Date():null;
       this.tick(o);
      }
     },
    
     Stop:function(id){
      var o=this['zxc'+id]
      o?clearTimeout(o.to):null;
     },
    
     init:function(o){
      var id=o.ID,t=o.Time,p=document.getElementById(id),t=typeof(t)=='string'?t:'0,0,0',t=t.split(/\D/)
      if (p){
       o.s=0;
       o.p=p;
       this['zxc'+id]=o;
       o.d=new Date();
       o.Start!==false?this.Start(id,o.Time,true):null;
      }
     },
    
     tick:function(o){
      clearTimeout(o.to);
      var s=o.s-Math.floor((new Date()-o.d)/1000),d=Math.floor(s/86400),h=Math.floor(s/3600)%24,m=Math.floor(s/60)%60,c=s%60
      o.p.innerHTML=(s>86400?((d>9?'':'0')+d)+' Days ':'')+(s>3600?((h>9?'':'0')+h)+' Hours ':'')+(s>60?((m>9?'':'0')+m)+' Minutes ':'')+(c>0?((c>9?'':'0')+c)+' Seconds ':'')
      if (s>=0){
       o.ss=s;
       o.to=setTimeout(function(){ zxcCountDown.tick(o); },1000);
      }
      else if (typeof(o.OnComplete)=='function'){
       o.OnComplete();
      }
     },
    
     sec:function(o,t){
      var t=typeof(t)=='string'?t:'0,0,0',t=t.split(/\D/);
      return Math.floor((t[3]&&isFinite(t[3]*1)?t[3]*86400:0)+(t[2]&&isFinite(t[2]*1)?t[2]*3600:0)+(t[1]&&isFinite(t[1]*1)?t[1]*60:0)+(t[0]&&isFinite(t[0]*1)?t[0]*1:0));
     }
    
    }
    
    
    zxcCountDown.init({
     ID:'count1',
     Time:'0:0:2:0',   //  seconds:minutes:hours:days
     Start:true,
     OnComplete:function(){
      alert('done');
     }
    });
    /*]]>*/
    </script>
    </body>
    
    </html>
    can you modify this to NOT reset on page download.. and countdown to a set time? can it automatically reset when the 2 hours are up? thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles