PDA

View Full Version : Countdown and redirect is off by like 1 sec



Humper
09-13-2006, 02:34 PM
I cant figure out why my redirect is off by about 1 sec from my countdown... I have both scripts in the body of the page... this seems to help because I tried to have the redirect in the header and it was off from the countdown by like 2-3 sec...

here is the redirect code (this is in a php file)

print "<script type=\"text/javascript\">"."\n";
print "window.onload=WindowLoad;"."\n";
print "function WindowLoad(event)"."\n";
print "{"."\n";
print "setTimeout(\"location = 'EquipReport.php';\", 20000);"."\n";
print "}"."\n";
print "</script>"."\n";


here is the countdown code

print "<form name='counter'><input type='text' size='6' name='d2' disabled style='border:0px; bgcolor:#FFFFFF;'></form> "."\n";
print "<script>"."\n";
print "<!--"."\n";
print "//"."\n";
print " var milisec=0"."\n";
print " var seconds=20"."\n";
print " document.counter.d2.value='20'"."\n";
print " function display(){"."\n";
print " if (milisec<=0){"."\n";
print " milisec=9"."\n";
print " seconds-=1"."\n";
print " }"."\n";
print " if (seconds<=-1){"."\n";
print " milisec=0"."\n";
print " seconds+=1"."\n";
print " }"."\n";
print " else"."\n";
print " milisec-=1"."\n";
print " document.counter.d2.value=seconds+\".\"+milisec"."\n";
print " setTimeout(\"display()\",100)"."\n";
print "} "."\n";
print "display()"."\n";
print "--> "."\n";
print "</script>"."\n";

anyone know why it is off?

blm126
09-13-2006, 09:40 PM
That is the difference between when the each section of code is executed.

Humper
09-14-2006, 12:38 AM
is there a way to combind the two so that when it reaches 0.0 it redirects? I cant figure out how to do that