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,709
    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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15324 seconds
  • Memory Usage 2,917KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates