/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] 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”;[/CODE]

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”;[/CODE]

anyone know why it is off?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Sep 13.2006 — Just glancing over your code I see:

Page loading time + Time to execute the steps before calling the next Timeout

One is being called inline, another is being called onload.

You are using setTimeout when you probably want to be using setInterval

Why don't you have the page redirect based on the "counting" portion. Makes more sense to me than having to "threads"

Eric
Copy linkTweet thisAlerts:
@HumperauthorSep 13.2006 — I dont know how to incorporate the two together... I tried putting the two together but I havent had any luck... any help woule be appreciated..
Copy linkTweet thisAlerts:
@HumperauthorSep 13.2006 — can this be put together in one script?
Copy linkTweet thisAlerts:
@HumperauthorSep 14.2006 — thanks!! I saw this and couldnt find my way back to it.. ?
Copy linkTweet thisAlerts:
@SaveSheepSep 14.2006 — Got any more for me? :-P
×

Success!

Help @Humper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...