1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Time limit / Limited time offer SCRIPT?

Discussion in 'HTML & JavaScript' started by Gianex, May 21, 2015.

  1. Gianex

    Gianex Junior Member

    Joined:
    Feb 21, 2013
    Messages:
    145
    Likes Received:
    17
    Basically what I need is a script that says "The offer will end in: (timer here)"
    And when the timer gets to 0, it will automatically reset to the starting time.

    I think there is alredy a similar script, if not, can anyone teach me how to do it?

    Thanks
     
  2. Gianex

    Gianex Junior Member

    Joined:
    Feb 21, 2013
    Messages:
    145
    Likes Received:
    17
    anyone knows? 15chars
     
  3. JamesHere

    JamesHere Jr. VIP Jr. VIP

    Joined:
    Jan 24, 2013
    Messages:
    495
    Likes Received:
    243
    Location:
    retentionpanel.com
    Home Page:
  4. Gianex

    Gianex Junior Member

    Joined:
    Feb 21, 2013
    Messages:
    145
    Likes Received:
    17
  5. lightning37

    lightning37 Newbie

    Joined:
    Dec 12, 2014
    Messages:
    21
    Likes Received:
    4
    Here is a script that will countdown any number of hours. If you want a different number of hours, simply change the number in the parentheses. You will need to add three html elements with the IDs of 'hours', 'minutes', and 'seconds'. LEt me know if you have any questions.

    Code:
    (function() {    
        var second = 1;
        var minute = second * 60;
        var hour = minute * 60;
        
        
        function beginCountdown(hours) {
            var seconds = (hours * hour);
            
            function countdownLoop() {
                var hoursRemaining = Math.floor((seconds / 60) / 60);
                var minutesRemaining = (Math.floor(seconds / 60) % 60);
                var secondsRemaining = (seconds % 60);
                        
                if (minutesRemaining < 10) {
                    minutesRemaining = "0" + minutesRemaining;
                }
                
                if (secondsRemaining < 10) {
                    secondsRemaining = "0" + secondsRemaining;
                }
                
                document.getElementById('hours').innerHTML = hoursRemaining;
                document.getElementById('minutes').innerHTML = minutesRemaining;
                document.getElementById('seconds').innerHTML = secondsRemaining;
                seconds--;
                if (seconds > -1) {
                    setTimeout(function(){countdownLoop();}, 1000);
                }
                if (seconds <= 0) {
                    seconds = (hours * hour);
                }
            }
            countdownLoop();
        }
        beginCountdown(3);
    })();
    JSFiddle Demo: (fix the URL) hxxp://jsfiddle.net/m0ukffx5/