Javascript Count down help
Javascript Count down help
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
Yes there're awful js countdowns on the web that's why ive made my own.
countdown.html
run the script and there your'll see it working.
bye!
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>

Orgullo Catracho
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Javascript Count down help
Urban Realms videos has a count down timer.
Re: Javascript Count down help
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.
The only videos I have seen are the ones for the browser based mmo. I can't download any others.
