Presenting my latest timer:
var eventDate = new Date(Date.parse(new Date) + 3600);
function countdown() {
var elapsed = Date.parse(eventDate) - Date.parse(new Date());
var seconds = Math.floor((elapsed / 1000) % 60);
var minutes = Math.floor((elapsed / 1000 / 60) % 60);
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return {
'minutes': minutes,
'seconds': seconds,
'total': elapsed
}
}
function initializeClock() {
var minutes = document.getElementById('minutes');
var seconds = document.getElementById('seconds');
var timeInterval = setInterval(function() {
minutes.innerHTML = countdown().minutes;
seconds.innerHTML = countdown().seconds;
if(minutes.equals(0) && seconds.equals(0))
{
timeInterval().stop();
$.ajax({
url: "Finish/Test",
type: 'POST',
success: function (result) {
if (result.success) {
$('#htmlElement').html(result.htmlElement);
}
}
});
}
},1000);
}
initializeClock();
<h2>@ViewBag.Title</h2>
<div id ='hmtlElement'>
.... continued in html format
[HttpPost]
public ActionResult Finish(ExamineTest examineTest)
{
var question = examineTest.Question.ToList();
_questions.AddRange(question);
_testService.SaveSolvedTest(examineTest);
return Json(new { success = true, htmlElement = RedirectToAction("Preview", "Test") });
}
[HttpGet]
public ActionResult Preview()
{
SolvedTest solvedTest = _testService.GetSolvedTest();
SolvedTestModel solvedTestModel = EntitySolvedTestConverter.ToModel(solvedTest);
return View("Finish", solvedTestModel);
}