...

View Full Version : Javascript Countdown



Laurence485
12-19-2011, 04:34 PM
hi,
i need to create a javascript countdown based on the times given. If the start time is 17:45 and the end time is 19:32 (in that format) for example, how would i create a countdown for the time between 17:45 and 19:32. If anyone could point me in the right direction that would be great!
thanks

VIPStephan
12-19-2011, 04:52 PM
Just wanted to point out that it’s not nice to post the same question on multiple forums (http://www.actionscript.org/forums/showthread.php3?t=268905). You’re just wasting the time of people trying to help in one thread when the question might have been solved in the other one.

Be patient and you will be helped eventually.

Also, could you please elaborate for what kind of project you need this countdown?

Laurence485
12-19-2011, 05:20 PM
this is for my website. I have created a reminder system (using JavaScript) where people will be reminded at the time entered e.g. if you enter 18:45 - you will be reminded at that time to do something. What i would like to do now is to add a countdown, so people know how long is left until the time.

Philip M
12-19-2011, 05:29 PM
this is for my website. I have created a reminder system (using JavaScript) where people will be reminded at the time entered e.g. if you enter 18:45 - you will be reminded at that time to do something. What i would like to do now is to add a countdown, so people know how long is left until the time.



Show your existing code and doubtless someone will modify it for you.

Laurence485
12-19-2011, 05:41 PM
var sethour = t.substr(0,2);
var setminute = t.substr(3,2);
var Hours = clockTime.substr(0,2);
var Minutes = clockTime.substr(3,2);
var Seconds = clockTime.substr(6,2);
time_countdown(Hours,Minutes,Seconds,t,sethour,setminute); //show countdown time until reminder

//print time left to div
function time_countdown(h,m,s,st,sh,sm){

var hoursleft = sh-h;
if(hoursleft<0)hoursleft+=24;
var minutesleft = sm-m-1;
if(minutesleft<0){
hoursleft-=1;
minutesleft=60+minutesleft;
}
var secondsleft = 0-s;
if(secondsleft<0)secondsleft=60+secondsleft;

if(hoursleft<10)hoursleft="0"+hoursleft;
if(minutesleft<10)minutesleft="0"+minutesleft;
if(secondsleft<10)secondsleft="0"+secondsleft;

$("#countdown").html(hoursleft+":"+minutesleft+":"+secondsleft);
}


This code prints the time left into the div with id "countdown"
e.g. the time printed could be "11:18:58"

I then need to have the time e.g. "11:18:58" turned into a countdown to 00:00:00 using setTimeout(), but i don't know how to do this

thanks

Philip M
12-19-2011, 06:36 PM
You have not shown the whole of your code - there is no function clockTime(). shown.

But the solution is simple. Wrap the whole thing in a function named (say) show(), and call the function repeatedly with

setInterval(show,1000);

Laurence485
12-19-2011, 09:55 PM
thanks, i've sorted it now



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum