Test Timer

[Total: 0    Average: 0/5]

This example sets a timer that starts as the page finishes loading.

Body Code:

Normally this next line would not be in the test - but it is shown here
to allow the example to run.
<a href="javascript:xxx()">Start Timer</a><BR>
<script language="javascript">
onload="xxx()"
function xxx() {if(resetVals) { setem(); }  if(doTimer) {tf=window.setTimeout('TimerFunc()',1000); }};
var doTimer=false;    
var resetVals=false; 
var ck=0;
var tf=0;
var timeUp=0;
var timeLeft=0;
var tcount=0;
function TimerFunc() {   tf=window.setTimeout("TimerFunc();",1000); 
   tcount++;
   timeLeft=180 - tcount;
   window.status = timeLeft + " Seconds remaining";
   if(timeLeft == 0) {
      window.clearTimeout(tf);      timeUp=1;      document.qform.submit();
   }
}function verifyAnswer() {
   if(timeUp==1) {
      return(true);
   }
   for(var i=0;i<5;i++) {
      if(document.qform.choize[i].checked == true) {
         window.clearTimeout(tf);
         return(true);
      }
   }
   if(ck==0) {
      ck=1;
      if(confirm("You have not selected an answer.If you click on 'OK', the system nwill move to the next question and this question will be scored as 'Wrong'.  nYou can not go back to this question later.")) {
         window.clearTimeout(tf);
         return(true);
      }
   }
   else return(true);
   return(false);
}
</script>
<form method="post" name="qform" action="/" onSubmit="return verifyAnswer();">
Pick An Answer:<BR>
Choice 1<input type="radio" name="choize" value="0"><BR>
Choice 2<input type="radio" name="choize" value="1"><BR>
Choice 3<input type="radio" name="choize" value="2"><BR>
Choice 4<input type="radio" name="choize" value="3"><BR>
Choice 5<input type="radio" name="choize" value="4"><BR>
<input type="submit" name="nextitem" value="Submit">
</form>
</div>
<script language="javascript">
// set the page as loaded.
doTimer = true;
</script>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *