/    Sign up×
Community /Pin to ProfileBookmark

Continuous Counter

I am a little novice at javascript. I have a client who wants a counter on their website. It is a church. They have service on Sunday @ 10 and then again on Wednesday @ 7 pm. So I would need the counter to counter down to the Sunday service and then til the Wednesday service. They want this to continue on their website for the duration. Can someone please help me with this particular code. Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsMay 18.2015 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
Sunday Service <span id="t1" ></span>
<br />
Wednesday Service<span id="t2" ></span>
<script type="text/javascript">
/*<![CDATA[*/

function zxcTimeTo(o){
var obj=document.getElementById(o.ElementID),n=new Date(),d=n.getDay(),os=d-o.Day,t,s,d,h,m;
if (obj&&typeof(o.Day)=='number'&&typeof(o.Hours)=='number'&&typeof(o.Minutes)=='number'){
clearTimeout(o.to);
if (os==0){
t=new Date(n.getFullYear(),n.getMonth(),n.getDate()+(n.getHours()*60+n.getMinutes()>o.Hours*60+o.Minutes?7:0),o.Hours,o.Minutes,10);
}
else {
t=new Date(n.getFullYear(),n.getMonth(),n.getDate()+(d-o.Day>0?7:0)-os,o.Hours,o.Minutes,10);
}
s=Math.floor((t-n)/1000),d=Math.floor(s/(60*60*24)),h=Math.floor(s/3600)%24,m=Math.floor(s/60)%60,s=s%60;
obj.innerHTML=d+' days '+((h<10?'0':'')+h)+' hours '+((m<10?'0':'')+m)+' minutes '+((s<10?'0':'')+s)+'seconds';
o.to=setTimeout(function(){ zxcTimeTo(o); },1000);
}
}

zxcTimeTo({
ElementID:'t1',
Day:0, // sunday
Hours:10,
Minutes:0
})

zxcTimeTo({
ElementID:'t2',
Day:3, // wedness day
Hours:19,
Minutes:0
})

/*]]>*/
</script>

</body>
</html>[/CODE]



or

[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<span id="t1" ></span>
<br />
<script type="text/javascript">
/*<![CDATA[*/

function zxcTimeTo(o){
var obj=document.getElementById(o.ElementID),s1=zxcToTime(o.Service1),s2=zxcToTime(o.Service2),n=new Date(),t,s,d,h,m;
if (obj&&s1&&s2){
t=s1<s2?s1:s2;
clearTimeout(o.to);
s=Math.floor((t-n)/1000),d=Math.floor(s/(60*60*24)),h=Math.floor(s/3600)%24,m=Math.floor(s/60)%60,s=s%60;
obj.innerHTML=d+' days '+((h<10?'0':'')+h)+' hours '+((m<10?'0':'')+m)+' minutes '+((s<10?'0':'')+s)+'seconds '+(s1<s2?o.Service1[0]:o.Service2[0]);
o.to=setTimeout(function(){ zxcTimeTo(o); },1000);
}
}

function zxcToTime(a){
if (typeof(a[1])=='number'&&typeof(a[2])=='number'&&typeof(a[3])=='number'){
var n=new Date(),d=n.getDay(),os=d-a[1],t;
if (os==0){
t=new Date(n.getFullYear(),n.getMonth(),n.getDate()+(n.getHours()*60+n.getMinutes()>o.Hours*60+o.Minutes?7:0),a[2],a[3],10);
}
else {
t=new Date(n.getFullYear(),n.getMonth(),n.getDate()+(d-a[1]>0?7:0)-os,a[2],a[3],10);
}
return t;
}
return false;
}

zxcTimeTo({
ElementID:'t1',
Service1:['Sunday Servive ',0,10,0],
Service2:['Wednesday Service ',3,19,0]
})

/*]]>*/
</script>

</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@jacquidmorganauthorMay 18.2015 — Thank you so much for your help with this. I really appreciate it more than you can imagine.
×

Success!

Help @jacquidmorgan 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...