Here is the function causing the trouble - I am trying to clean it up and make it more efficient/easier to read. When I make a change in the conditional statement it zeros the global variable .
by global - I mean it is declared by the statement outside of any function, then set inside another function by the statement
Code:
finishTime=now.getTime()+(60*mins+secs)*1000+(cent*10);
Code:
function chrono()
{
now=new Date();
var timeToRun=finishTime-now.getTime();
totalTime.setTime(timeToRun);
mins=totalTime.getMinutes();
secs=totalTime.getSeconds();
cent=Math.floor(totalTime.getMilliseconds()/10);
display(); // prints out mins, secs and cent - it does not change them.
if(timeToRun>100) // go round the function again - this causes the trouble
{
counter=setTimeout("chrono()",5);
}
else // leave the loop - countdown completed - this works all the time
{
document.getElementById("pinger").innerHTML=pinger;
clearTimeout(counter);
reset();
}
// alternative comparison that is less efficient but works! (cent>10 || secs!=0 || mins!=0)
}
Any suggestions much appreciated.
Still thinking and still very puzzled, but putting this together has helped a little.
PS testing in Firefox3.0.5, and the full html file is attached with all the javascript code.
Bookmarks