PDA

View Full Version : Status bar countdown timer exceeds limit



jaynoble
08-16-2009, 05:01 AM
I am passing no more than 15 minutes to the code below. The problem is sometimes it works and stops at 0 and other times it just restarts from 60 or 70 minutes. It is run in an ASP website.

Is there a problem with the code?

I added in code to prevent the initial time from being more than 15 minutes, but that is not working.

I would also like a check to verify the elapsed time of 15 minutes has not passed (in case it does reset to 60+ minutes).

Thank you in advance for your assistance.



<script language="JavaScript">
<!--
function StatusBarText(txt) {
window.status=txt;
}
// -->
</script>

<script language="javascript">

function showTimer(TimerStyle)
{
timeLeft = startTime - currentTime;

if (timeLeft > 59)

minutes = parseInt(timeLeft / 60);
else
{
minutes = 0;
}

seconds = parseInt(timeLeft - minutes * 60);

if (minutes < 10)

minutes = "0" + minutes;

if (seconds < 10)

seconds = "0" + seconds;

switch (TimerStyle)
{
case 1 :
window.status = minutes + ":" + seconds + " remaining to guess the Hangman Word/Phrase.";
break;
default :
window.status = minutes + ":" + seconds + " to send information back to the webserver -- or -- be logged off the website.";
break;
}
window.setTimeout(function(){ getTime(TimerStyle); },1000);
}

function setTimer(PassedMinutes,TimerStyle)
{

var time = new Date();
mins = time.getMinutes();
secs = time.getSeconds();
startTime = mins * 60 + secs;
if(PassedMinutes > 15)
{
PassedMinutes = 15
}
startTime += PassedMinutes * 60; //set time in seconds
getTime(TimerStyle);

}

function getTime(TimerStyle)
{
var time = new Date();
mins = time.getMinutes();
secs = time.getSeconds();
currentTime = mins * 60 + secs;

if(currentTime > startTime) //when time's up
{
switch (TimerStyle)
{
case 1 :
window.location.href = "hangman.asp";
break
default :
window.location.href = "logout.asp?msg=1";
}
// alert("Your time is up!"); //alert the user
// window.location.href = "logout.asp?msg=1"; //or redirect them to another page
}
else
showTimer(TimerStyle);
}
</script>