Time limit / Limited time offer SCRIPT?

Gianex

Junior Member
Joined
Feb 21, 2013
Messages
149
Reaction score
21
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
 
anyone knows? 15chars
 
This is a countdown timer script: http://www.rmkwebdesign.com/Countdown_Timers/Style_1c.html
 
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/
 
Back
Top