PDA

View Full Version : countdown to hour:minute HELP!


Ricky158
11-20-2002, 02:42 AM
i need a script to countdown to a certain time every night (10pm every night). so if it's 4:15pm, and i'm viewing the script on my site, it will say "Next chat to begin in 5 hours and 45 minutes". and if the person views the counter between 10pm and 11pm a link is displayed to "Go Chat" (it is a script counting down to the next official chat time, and when chat is in session, the user has a nice link right infront of them). any more info needed, i'll be glad to share.

thanks ;)

x_goose_x
11-20-2002, 03:07 AM
<html>

<head>

<script>

t = 22;

function ttl() {
d = new Date();
h = d.getHours();
m = 60-d.getMinutes();
if (h>=t) {
h = (23+t)-h;
}else{
h = (t-1)-h;
}
if (m==60) {
m = 0;
h +=1;
}
document.form1.timeleft.value = h+" hours, "+m+" minutes";
}

setInterval("ttl()",30000);
setTimeout("ttl()",10);

</script>

</head>

<body>

<form name="form1">
<input type="text" name="timeleft">
</form>

</body>

</html>

Ricky158
11-20-2002, 03:36 AM
that script works fine, but i only have two requests;

1) it be with document.write instead of in a textbox (i only know that that's the expression that you use, i dont know how to apply it)

2) as it is within the 10pm - 11pm hour, it should show up as a link (you can just refer to it as "CHATLINK" for now, i'll replace it later)


11:01pm (day 1) - 9:59pm (day 2) = countdown to 10pm
10:00pm - 11:00pm = link

so if it was 3pm, it should say "Next chat to begin in 7 hours"
if it was 10:37pm, it should say "Chat is in session. {link to chat}Click here{/link to chat}.


i hope that clears it up.


thanks

x_goose_x
11-20-2002, 07:03 PM
<html>

<head>

<script>

t = 22;

function ttl() {
d = new Date();
h = d.getHours();
m = 60-d.getMinutes();
if (h>t) {
h = (23+t)-h;
}else if (h==t){
document.all.timeleft.innerHTML = "Chat in progress. Click <a href='#'>HERE</a> to enter.";
return false;
}else{
h = (t-1)-h;
}
if (m==60) {
m = 0;
h +=1;
}
document.all.timeleft.innerHTML = "Next chat in "+h+" hours, "+m+" minutes";
}

setInterval("ttl()",30000);
setTimeout("ttl()",10);

</script>

</head>

<body>

<div id="timeleft"></div>

</body>

</html>

Ricky158
11-21-2002, 01:58 AM
perfect. thanks very much, goose :thumbsup: