Results 1 to 3 of 3

Thread: Countdown and redirect is off by like 1 sec

  1. #1
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Countdown and redirect is off by like 1 sec

    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)
    Code:
    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
    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?

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    That is the difference between when the each section of code is executed.

  3. #3
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •