macwiz
07-18-2008, 01:11 AM
This script will execute other functions when time runs out. I found it very useful when timing Radio Button quizzes and what not that are scored with JavaScript. Simply add this to your page:
<body onload="begintimer();">
There are comments in the appropriate places.
<script language="javascript">
//enter limit in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="30:00"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function begintimer(){
if (!document.images)
return
if (parselimit==1)
{
//ACTIONS HERE!!!!
}
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left"
else
curtime=cursec+" seconds left"
window.status=curtime
setTimeout("begintimer()",1000)
}
}
</script>
Tell me what you think please. Thanks.
<body onload="begintimer();">
There are comments in the appropriate places.
<script language="javascript">
//enter limit in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="30:00"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function begintimer(){
if (!document.images)
return
if (parselimit==1)
{
//ACTIONS HERE!!!!
}
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left"
else
curtime=cursec+" seconds left"
window.status=curtime
setTimeout("begintimer()",1000)
}
}
</script>
Tell me what you think please. Thanks.