...

View Full Version : Help with Javascript countdown..



lengman
12-17-2011, 11:49 PM
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)


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 :):thumbsup:

venegal
12-18-2011, 01:18 AM
Most importantly, you can't have multiple functions with the same name in the same scope. Change that, so the code is sensible enough for us to see what you're trying to do.

Once you've done that, you might also want to tell us what you expect your code to do vs. what it's actually doing.

lengman
12-18-2011, 01:50 AM
Thanks for the reply, my knowledge of Javascript = 0.

Basically I was guided through this by a friend who knows very little.

There is a crime timer on my rightmenu. I want that to physically tick down instead of only ever changing when the page is refreshed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum