Problem in Displaying a Stop Watch

0 views
Skip to first unread message

Puneet Pandey

unread,
Apr 26, 2008, 5:07:53 AM4/26/08
to BANGALORE RUG-Ruby Users Group
Hello Guys,

Hope You all are Doing Well in Your Corresponding Organizations. Guys I m Stuck In One Problem, Hope Anyone can Help Me Out of this.

My Problem is:

There are Two Sections in my Website, one is admin and one is User. Admin can Create Exams which Consists of Questions, Possible Options, Image Related to the Specific Question and One Correct Answer, Once the Admin has Done With This, he/she can attach a timer, that How Long will this Exam take place.

For Example an Admin Creates 10 questions for a Particular Exam and at the end he adds that this exam is of 1 hour.

Now on the User side, When Someone played this test, what I want is, a Stopwatch should Come, Which Will Start according to the user defined time, for example  [00:59:59 (hh:mm:ss)] in other words i want to display a countdown stopwatch, apart from that I also want to start session when someone clicks on back or want to try to refresh the page the session and that stopwatch should destroy.

I need Your Help. Please Show me Some Way so that I can Proceed. I m waiting for Your Response

--
___________________

Puneet Pandey
Senior Software Engineer
Safew Technology Labs
pun...@safewlabs.com
http://www.safewlabs.com
http://puneetitengineer.wordpress.com

Martin DeMello

unread,
Apr 27, 2008, 10:18:00 PM4/27/08
to bangal...@googlegroups.com
I've found the best thing to do in these cases is to invert your
control flow. Write a javascript function that does what you want, and
makes ajax calls to your backend to get data, html fragments, etc.

martin

Satish Kota

unread,
Apr 28, 2008, 1:26:19 AM4/28/08
to bangal...@googlegroups.com
Hey Puneeth,
 
Talk to ganes...@heurionconsulting.com. He has developed an online examination application using a similar stop watch..which was a javascript application
 
Thanks and Regards
Satish N Kota

Ganesh Mohan

unread,
Apr 28, 2008, 8:14:17 AM4/28/08
to bangal...@googlegroups.com

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.

Thanks & Regards
 Ganesh Mohan

www.heurionconsulting.com

Reply all
Reply to author
Forward
0 new messages