This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Count down timer

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure but try using IFRAME
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

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


Thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That still won't prevent a refresh from resetting everything. If the timer is important, store its value in the session.
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added 2 setter and getter for min and secs in form bean.. Now it's working perfectly.. Thanks for all your support
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic