Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2006, 12:47 AM
Registered User
 
Join Date: Mar 2006
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





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





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