SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I create an auto reseting countdown timer

    Hello:

    I need help getting my countdown timer to reset itself when the timer is up, and then countdown to a new date. I created it for counting down to the launch of Nintendo Wii and my goal is to have it countdown to the launch in all 3 territories.

    Nevermind, I figured it out. Sorry to bother you all!
    Last edited by winlonghorn; Sep 4, 2006 at 20:37.

  2. #2
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ithaca, MI USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    winlonghorn,

    I don't know anything about javascript yet, but I really need to set a timer up on a site. They want it to count down to a specific day and time. Where can I find a script that does this? It sounds similar to what you are doing with your countdown.

    Thanks

  3. #3
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MacroFats
    winlonghorn,

    I don't know anything about javascript yet, but I really need to set a timer up on a site. They want it to count down to a specific day and time. Where can I find a script that does this? It sounds similar to what you are doing with your countdown.

    Thanks

    That is pretty easy. You can have my script if you want for reference. I can even customize it for you so that you don't have functionality you don't want. Here is the javascript code:

    function naLaunch()//function to start timer.
    {
    var DSTAdjust = 0;//Daylight Savings
    oneMinute = 1000 * 60;
    var oneDay = oneMinute * 60 * 24;
    var expired = 0;//used as a boolean value to determine if the date has been reached.
    time = new Date();//set up the current date
    if (time.getTime() >= timerEnd.getTime())
    {
    expired = 1;
    }
    else
    {
    DSTAdjust = (timerEnd.getTimezoneOffset( ) - time.getTimezoneOffset( )) * oneMinute;
    var diff = Math.abs(timerEnd.getTime( ) - time.getTime( )) - DSTAdjust;

    var days = Math.floor(diff/oneDay);
    var hours = Math.floor(diff/(60*oneMinute)) % 24;
    var minutes = Math.floor(diff/oneMinute) % 60;
    var seconds = Math.floor(diff/1000) % 60;
    //var mseconds = diff % 1000;
    }
    if (expired == 1)
    {
    //code to execute when timer runs out.
    }
    else
    {
    document.getElementById('days2').innerHTML = Math.floor(days/100);
    document.getElementById('days1').innerHTML = Math.floor((days%100)/10);
    document.getElementById('days0').innerHTML = days % 10;

    document.getElementById('hours1').innerHTML = Math.floor(hours/10);
    document.getElementById('hours0').innerHTML = hours % 10;

    document.getElementById('mins1').innerHTML = Math.floor(minutes/10);
    document.getElementById('mins0').innerHTML = minutes % 10;

    document.getElementById('secs1').innerHTML = Math.floor(seconds/10);
    document.getElementById('secs0').innerHTML = seconds % 10;

    //document.getElementById('msecs2').innerHTML = Math.floor(mseconds/100);
    //document.getElementById('msecs1').innerHTML = Math.floor((mseconds%100)/10);
    //document.getElementById('msecs0').innerHTML = mseconds % 10;
    setTimeout(naLaunch, 100);
    }
    if(document.getElementById('days2').innerHTML == 0 && document.getElementById('days1').innerHTML <= 1 && document.getElementById('days0').innerHTML <= 9){
    document.getElementById('timer').style = "color: #777777;";
    }
    if(document.getElementById('days2').innerHTML == 0 && document.getElementById('hours0') <= 12){
    document.getElementById('timer').style = "color: #333333;";
    }
    if(document.getElementById('days0').innerHTML == 0 && document.getElementById('hours0').innerHTML < 1){
    document.getElementById('timer').style = "color: #991111;";
    }
    }

    document.write("<div id='msg' class='msg' align='center'><b>Wii Launches In North America In</b></div>"+"<table id='timer' align='center' class='timer' cellpadding='0' cellspacing='0'>"+
    "<tr><td id='days2'>0</td><td id='days1'>0</td><td id='days0'>0</td><td>&nbsp;</td><td id='hours1'>0</td><td id='hours0'>0</td><td>&nbsp;</td><td id='mins1'>0</td><td id='mins0'>0</td><td>&nbsp;</td><td id='secs1'>0</td><td id='secs0'>0</td></tr>"+
    "<tr class='labels'><td colspan='3' align='center'>Days</td><td>&nbsp;</td><td colspan='2' align='center'>Hours</td><td>&nbsp;</td><td colspan='2' align='center'>Mins</td><td>&nbsp;</td><td colspan='2' align='center'>Secs</td></tr><tr><td colspan='16' align='right'></tr></table>");

    window.onload=naLaunch;

    HTML PAGE:

    <Html>
    <Head>
    <Title>Wii Countdown!</Title>
    <Script type="text/javascript" src="wiicountdown.js"></Script>
    <Style>
    table.timer{
    font: bold 24pt Continuum, Arial, Helvetica;
    color: #999999;
    }
    table.timer.td{
    padding: 0;
    margin: 0;
    }
    table.timer tr.labels td{
    font-size: 10pt;
    }
    .msg{
    font: bold 12pt Continuum, Arial, Helvetica;
    color: #000055;
    }
    </Style>
    </Head>
    <Body id="main">
    <Script type="text/javascript">
    <!--
    var timerEnd = new Date("October 22, 2006 00:00:00");//sets end date
    naLaunch();

    //-->
    </Script>
    </Body>
    </Html>

    Hope this helps.
    Last edited by winlonghorn; Sep 7, 2006 at 17:15. Reason: Code section added

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ithaca, MI USA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I'm going to try it and see how it works out. I appreciate the help. If I have any problems, I'll let you know.

    M.F.

  5. #5
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MacroFats
    Thanks! I'm going to try it and see how it works out. I appreciate the help. If I have any problems, I'll let you know.

    M.F.
    Ok, great. Glad I could be of assistance.


Bookmarks

Posting Permissions

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