I have a timeout function for an online test page that disables the test input when the allowed time expires (15 minutes), which is working OK.
I also want to dispaly a countdown clock (seconds and minutes only) to show how much time is left.
The timeout script is as follows: How can I incorporate a countdown into this script, which will show the seconds running down.
<script type="text/javascript">
var minutes = 15;
var timeLeft = minutes*60*1000;
var tId = "";
var leave = "";
function countdown() { timeLeft -= 1000; }
window.onload=function() {
leave = setTimeout("nextPage()", timeLeft);
tId = setInterval('countdown()',1000);
}
function nextPage(){
//assuming you have <form id="English1"...>
var f = document.getElementById("English1");
for( var i=0; i < f.elements.length; ++i)
{
if( String(f.elements[i].type).toLowerCase() != "submit" )
f.elements[i].disabled=true;
}
}
function activate(f){
if (timeLeft > 60000 && confirm('Are you sure you want to leave the English test? You still have some time left to go back and check your answers. If you are sure you want to go on to the Verbal Reasoning Test, please click OK button. Otherwise, click Cancel button to return to the English test and use the remaining minutes to improve your English score.')) return false;
for( var i=0; i < f.elements.length; ++i)
{
f.elements[i].disabled=false;
}
return true;
}
</script>