Page 1 of 1
Javascript Count down help
Posted: Sun Dec 25, 2011 10:04 pm
by Cdaman
How do I make a javascript countdown (I want it to start at 2 minutes and count down to 0 seconds before running some code) I have looked on the web and all that I found is how to make so that it shows a countdown to do with the date (Days, Months, Years until something).
Re: Javascript Count down help
Posted: Mon Dec 26, 2011 4:34 am
by Ark
Yes there're awful js countdowns on the web that's why ive made my own.
countdown.html
Code: Select all
<html>
<head>
<script type="text/javascript">
function countdown(countdownId)
{
if(mins == 0)
{
if (hours==0)
{
hours = 0;
hours2=(hours<10?"0"+hours:""+hours);
mins2=(mins<10?"0"+mins:""+mins);
sec2=(sec<10?"0"+sec:""+sec);
countdownId.innerHTML=hours2+":"+mins2+":"+sec2;
return;
}
else if(sec==0)
{
hours -= 1;
mins = 59;
sec = 59
hours2=(hours<10?"0"+hours:""+hours);
mins2=(mins<10?"0"+mins:""+mins);
sec2=(sec<10?"0"+sec:""+sec);
countdownId.innerHTML=hours2+":"+mins2+":"+sec2;
return;
}
else
{
sec-=1;
hours2=(hours<10?"0"+hours:""+hours);
mins2=(mins<10?"0"+mins:""+mins);
sec2=(sec<10?"0"+sec:""+sec);
countdownId.innerHTML=hours2+":"+mins2+":"+sec2;
return;
}
}
if (hours == 0 && mins == 0 && sec == 0)
{
clearInterval(countdownVar); // ENDS THE COUNTDOWN.
}
else if(sec==0)
{
mins -= 1;
sec = 59;
hours2=(hours<10?"0"+hours:""+hours);
mins2=(mins<10?"0"+mins:""+mins);
sec2=(sec<10?"0"+sec:""+sec);
countdownId.innerHTML=hours2+":"+mins2+":"+sec2;
}
else
{
sec -=1;
hours2=(hours<10?"0"+hours:""+hours);
mins2=(mins<10?"0"+mins:""+mins);
sec2=(sec<10?"0"+sec:""+sec);
countdownId.innerHTML=hours2+":"+mins2+":"+sec2;
}
} <!-- ENDS -->
</script>
</head>
<body>
<p id="countdown">blabla</p>
<script type="text/javascript">
var hours=1;
var mins=0;
var sec=5;
var countId=document.getElementById("countdown");
hours2=(hours<10?"0"+hours:""+hours);
mins2=(mins<10?"0"+mins:""+mins);
sec2=(sec<10?"0"+sec:""+sec);
countId.innerHTML=hours2+":"+mins2+":"+sec2;
var countdownVar=setInterval("countdown(countId)",1000);
</script>
</body>
</html>
run the script and there your'll see it working.

bye!
Re: Javascript Count down help
Posted: Mon Dec 26, 2011 7:57 pm
by hallsofvallhalla
Urban Realms videos has a count down timer.
Re: Javascript Count down help
Posted: Mon Dec 26, 2011 10:46 pm
by Cdaman
thank you, i will try that.
The only videos I have seen are the ones for the browser based mmo. I can't download any others.
