View Single Post
Old 12-17-2011, 10:49 PM   PM User | #1
lengman
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lengman is an unknown quantity at this point
Help with Javascript countdown..

Hi all,

This is my first post on a forum regarding help so I'm sorry in advance.

I currently have a text based MMORPG.

I am trying to create a countdown timer for my functions(Crime, Car Steal and so on)

Code:
    window.setTimeout("Tick()", 1000);

    function Tick() {
        window.setTimeout("Tick()", 1000);
    }
	var Timer;
var TotalSeconds;


function CreateTimer(TimerID, Time) {
    Timer = document.getElementById(TimerID);
    TotalSeconds = Time;
    
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function Tick() {
    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    Timer.innerHTML = TotalSeconds;
}

function Tick() {
    if (TotalSeconds <= 0) {
        alert("Available")
        return;
    }

    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    var Seconds = TotalSeconds;
    
	var Days = Math.floor(Seconds / 86400);
    Seconds -= Days * 86400;
	
    var Hours = Math.floor(Seconds / 3600);
    Seconds -= Hours * (3600);

    var Minutes = Math.floor(Seconds / 60);
    Seconds -= Minutes * (60);


    var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)


    Timer.innerHTML = TimeStr + "Organised Robbery!";
}


function LeadingZero(Time) {

    return (Time < 10) ? "0" + Time : + Time;

}
Any help with regards to this would be greatly appreciated.

Thanks in advance
lengman is offline   Reply With Quote