Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2006, 12:47 AM
Registered User
 
Join Date: Mar 2006
Location: cochin, kerala, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dua_salam@yahoo.com
Default how to stable count down timer!!

hey guys!!
i am doing an online project in jsp + javascript!
its an online examination project where i m using countdown timer.
 i am taking each time one question from database which is in DB2.
 timer is working perfect but whenevr i load the same page again timer code gets execute again n start from its initial point.
  is thr any idea to stop it?? i mean i only need to execute timer once when i m loading the page i am loading every question again and again on same page.
i m newbie in javascript so i dont have much idea how to control these things in javascript. the remaining page is written in jsp. like database connectivity n retrieval of data from database.TIMER code is written in javascript. i m putting the sample of the code here so u guys can make out wht i need to stop it whn i will again load the same page for retriving anothe rquestion from database .
please help me out with any possible solution available.

  here the code is
<HTML>
<HEAD>

<TITLE>Timer</TITLE>
</HEAD>

<%

   int id = 0;
  String parm=request.getParameter("id");
   if (parm != null)
    id = Integer.parseInt(parm);

  %>

<BODY onload="startTimer()">
  <DIV ALIGN="center">
Countdown Timer
<FORM>



    Time Elapsed: <br>
    <INPUT TYPE="text" NAME="timeLapse" VALUE=""><BR>
    Time Remaining: <br>
    <INPUT TYPE="text" NAME="timerDisplay" VALUE=""><BR>
</FORM>
</DIV>
<SCRIPT LANGUAGE="JavaScript">
<!--
//var running = false;
  var running;
var endTime = null;
var timerID = null;
var theTime = null;
var minutes = null;
var seconds = null;
var start = null;
// var start;

document.bgColor = "#FAFAD2";

function startTimer() {
    running = true;
    var now = new Date();
    start =now.getTime();
    //var minutes = document.forms[0].minutes.value;
    //minutes = lapse.getMinutes();
    //seconds = lapse.getSeconds() + 1;
        //var seconds = document.forms[0].seconds.value;
    var setTime = 1000 * 60 * minutes + 1000 * seconds;

    endTime = start + setTime;

    showCountDown()

}

function showCountDown() {
    document.bgColor = "#7FFFD4";
    var present = new Date();
    moment = present.getTime();
    if (endTime - moment<= 0) {
        stopTimer();
        document.forms[0].timerDisplay.value = "TIME'S UP!";
        turnRed();
                 move();
    } else {
        var lapse = new Date(moment - start);
        var minLapse = lapse.getMinutes();
        var secLapse = lapse.getSeconds() + 1;
        var timeLapse = minLapse;
        timeLapse += ((secLapse < 10) ? ":0" : ":") + secLapse;
        document.forms[0].timeLapse.value = timeLapse;
        var delta = new Date(endTime - moment);
        var theMin = delta.getMinutes();
        //minutes = delta.getMinutes();
        var theSec = delta.getSeconds();
        //seconds = delta.getSeconds();
        theTime = theMin;
        theTime += ((theSec < 10) ? ":0" : ":") + theSec;
        document.forms[0].timerDisplay.value = theTime;

        if (running) {
            timerID = setTimeout("showCountDown()",1000)
        }
    }


}

function stopTimer() {
    document.forms[0].timerDisplay.value = theTime + " TIMER STOPPED";
    clearTimeout(timerID);
    running = false;
    setTimeout("document.bgColor = '#FAFAD2'", 3000);
}

function turnRed() {
    document.bgColor = "#000000";
    setTimeout("document.bgColor = '#FF0000'", 500);

}


function move() {
//alert ("TIME'S UP");
window.location = 'http://localhost:8080/Online/login.jsp'
// alert ("TIME'S UP");
}

// -->
</SCRIPT>


Click <a href="fin_time.jsp?id=<%=id+1 %>">For Next Question</a>

<BR><BR>
</BODY>
</HTML>

Krishna
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: Count = Count + 1 elayaraja.s XSLT 3 July 18th, 2008 03:21 AM
Timer Dhanapal ADO.NET 2 April 16th, 2007 04:58 AM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
Stable Version of VWD mar0364 ASP.NET 1.0 and 1.1 Basics 4 April 12th, 2005 03:36 PM



All times are GMT -4. The time now is 04:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.