I have a small project that involves timer, automatic page redirect and database submission. I am new to js so iam just doing what i know and what i found on the interent.
In Summary
I have qna (10 to 20 questions or more) test that require to work with the timer.
Manual submission
Once the user completed (all or partial) the answers they click the submit button and all the values are submitted to the database with the current timer position.
Timer runs out
If the timer runs out a popup window appears with a submit button and click that will submit the current form and redirects to the next page with the entered values.
Are the Questions are fixed?
The questions are automatially generated and saved to the database. The questions are take from the Database and displayed to the user.
Basic form
<form action="submitted.php" method="post" id="myForm">
<label for="q1">QUESTION-1-FROM-DATABASE</label>
<input type="text" name="ans_1">
<label for="q1">QUESTION-2-FROM-DATABASE</label>
<input type="text" name="ans_2">
<!-- more -->
<button type="submit" id="formSubmit">Submit form</button>
</form>
Timer jquery Plugin
I am using the Simple.Timer plugin from Csouza (https://csouza.me/jQuery-Simple-Timer/). The timer feature is simple and i was able to redirect
$(document).ready(function(){
$('.timer').startTimer({
onComplete: function(){
var msg = confirm("Time runs out!");
if( msg == true ) {
$("#myForm").submit();
return false;
}
}
});
});
The problem is how can i grab the current time (the time it was redirected). i also want to save that to the database.
Much appreciated.