PHP Quiz Timer

Design an online quiz timer using JavaScript and PHP:

1) To create a table to store  timer in minutes

CREATE TABLE  `cnsh_lms`.`edu_tests_extra` (
`test_id` mediumint(8) unsigned NOT NULL auto_increment,
`timer` tinyint(4) unsigned NOT NULL,
`num_timer` bigint(10) unsigned NOT NULL default '0',
PRIMARY KEY  (`test_id`)
) ENGINE=MyISAM AUTO_INCREMENT=82 DEFAULT CHARSET=utf8;

2)  To display a count down timer, the initialized  minutes  from $row_2['num_timer']  in above table. When down to 0, the form quiz is submitted.

<div style="font-weight: bold" id="quiz-time-left"></div>

<script type="text/javascript">
var max_time = <?php echo $row_2['num_timer'] ?>;
var c_seconds = 0;
var total_seconds = 60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init() {
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}

function CheckTime() {
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0) {
setTimeout('document.quiz.submit()',1);
} else {
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}
}

init();
</script>

3) If you click refresh or go to another webpages, the for will be submitted auotomatically
<script type="text/javascript">
function finishpage() {
alert("unload event detected!");
document.quiz.submit();
}

window.onbeforeunload= function() {
setTimeout('document.quiz.submit()',1);
}
</script>

4. The form
 <form method="post" name="quiz" id="quiz_form" action="take_test1.php" >
</form>

Comments

  1. Excellent, ideal, supreme blog which is the wonderful describe whole blog on net. Very accurate and precise blog write by your side on net. Thanks you from your side on net. I believe your blog is the best one as compare to all the blog on net.

    http://ilearn24x7.com/online-skill-quiz-test/

    ReplyDelete
    Replies
    1. Thank You Karam Singh. Thank you very much for precious comment.

      Delete
  2. Remarkably excellent written blog on the internet. Thanks you very much for posting the blog..

    http://ilearn24x7.com/online-php-quiz-test

    ReplyDelete
  3. very nice thank yoooou

    ReplyDelete
  4. Sir but when page we click on next qusion button its again reset the timer
    Which not tequire to reseting

    ReplyDelete

Post a Comment

Please feel free to comment. I would love to hear feedback.