Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-30-2012, 10:17 PM   PM User | #1
Sparktastic
New Coder

 
Join Date: Apr 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
Sparktastic is an unknown quantity at this point
JS Countdown Refresh?

What can I add to my code to refresh the timer's output?

here's my Script:
Code:
<script language="javascript" type="text/javascript">

today  = new Date();
todayEpoch  = today.getTime();

target = new Date("03 May, 2012"); 
targetEpoch = target.getTime();

daysLeft = Math.floor(((targetEpoch - todayEpoch) / (60*60*24)) / 1000);
hoursLeft = Math.floor(((targetEpoch - todayEpoch) / (60*60)) /1000);
minutesLeft = Math.floor(((targetEpoch - todayEpoch) / (60)) /1000);
secondsLeft = Math.floor(((targetEpoch - todayEpoch)) /1000);

hours = Math.floor((hoursLeft)-((daysLeft)*24)); 
minutes = Math.floor((minutesLeft)-(hoursLeft*60));
seconds = Math.floor((secondsLeft)-(minutesLeft*60));
</script>
and how it would be placed in a html document (snippet):
Code:
I  am 18 in: <br>
<script>document.write(daysLeft);</script> Days, <br>
<script>document.write(hours);</script> Hours, <br>
<script>document.write(minutes);</script> Minutes and <br>
<script>document.write(seconds);</script> seconds! <br>
Any help appreciated!
Sparktastic is offline   Reply With Quote
Old 04-30-2012, 10:35 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
To have the countodwn update within the page you need to throw away all that antiquated JavaScript and start again.

document.write can only run before the page loads and is only useful where you don't have access to generate the output on the server.

See http://javascript.about.com/library/blcount1.htm for the sort of code you need to be able to have the countdown timer actually count down.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
countdown, javascript, script, timer

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:39 AM.


Advertisement
Log in to turn off these ads.