martin
Hi Puneet,
I am basically a .Net Programmer. Yes Of Course I have done this but in C# & ASP.net. I have no much idea in Ruby on Rails. I have used JavaScript for this, Hope this Helps you.
As per your Example If Admin adds an Exam with 10 questions & 1 Hour Duration then the time format looks like 01:00:00 (Hours:Minutes:Seconds)
You need to use the following Javascript that I used in my ASP.Net
You need to send the Hours, minutes & seconds ex: 1:00:00
<script>
<!--
var hours=document.getElementById('HidHours').value;
var minutes=document.getElementById('HidMinutes').value;
var seconds=document.getElementById('HidSeconds').value;
function display(){
if (seconds<=0)
{
if((hours==0)&&(minutes==0))
seconds=0;
else
{
seconds=60;
minutes-=1;
}
}
if (minutes<=0)
{
if((hours<0)&&(minutes<0))
{
hours = minutes = seconds = 0;
}
else
{
if((hours==0)&&(minutes==0))
hours=minutes=0;
if((hours>0)&&(minutes<0))
{
minutes=59;
hours-=1;
}
}
}
if ((minutes<=-1)||(hours<=-1))
{
if(hours<=-1)
{
minutes=0;
hours+=1;
}
else
minutes-=1;
seconds=0;
minutes+=1;
}
else
if(seconds>0)
seconds-=1;
document.getElementById('counter').value=hours+":"+minutes+":"+seconds;
setTimeout("display()",1000);
}
display();
-->
</script>
and the 'counter' is a textbox or label which displays the count down Time.
And whenever the Page gets Refreshes you need to check that this count down is equal to 00:00:00 If so redirect to Exam End/Result Page.
And one more thing here when a user gets back to previous page or next page then the page refreshes. While refreshing If you want the counter to be continue as it is then you need to set Page Auto PostBack to false and If you want the counter to be restarted then you need to set Page Auto PostBack to True.
You can try this Hope this helps you, Still If you have any doubts please feel free to ask me.