This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP Count down timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Count down timer" Watch "JSP Count down timer" New topic
Author

JSP Count down timer

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Hi

I have a designed a small mock test in web application. I have tried to use javascript countdown timer, But no use, when every time I clicked the next or previous button the page refreshed and the timer reset to beginning. Any way I can use the live timer from jsp or servlet. Please assit me

Thanks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I'm not sure but try using IFRAME


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You *are* using a timer. What you're not realizing is how browsers and JavaScript work--a page's JavaScript only lives as long as that page is loaded. Load a new page, you're starting "from scratch".
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
David,

I realize the issue.. Thats why am posting here for help


Thanks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

All the online test I had given, follow either of this for timer.
1. Load next question in IFRAME.
2. Fetch next question using AJAX

If you really want one question per page, then try passing the current time as a hidden field.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

That still won't prevent a refresh from resetting everything. If the timer is important, store its value in the session.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
I think, storing the time in the session and passing it (displaying) on webpage and decrementing it using javascript, and when "next" is clicked resending (new value) back also has one advantage, the time it takes during trasit (next page load) is not lost. I think it is ideal way than using an IFRAME where it keeps on ticking even when the page is not yet loaded!
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Added 2 setter and getter for min and secs in form bean.. Now it's working perfectly.. Thanks for all your support
 
GeeCON Prague 2014
 
subject: JSP Count down timer