I have 2 scipts that I am trying to get to run on the same page. One
is a time/date script, the other is a countdown script (i.e. countdown
days, hours, mins until a given date). They both work independent of
each other, however, when both are on the page, the "active clock"
does not work. I am assuming it is because some of the variables are
the same???
Can anyone help please?!?!
Here are the 2 scripts:
**Active Clock that displays current time/date info**
<!-- Begin
var dayarray=new Array("Sunday", "Monday","Tuesd ay","Wednesday" ,"Thursday","Fr iday","Saturday ")
var montharray=new Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se ptember","Octob er","November", "December")
function getthedate(){
var mydate=new Date()
var year=mydate.get Year()
if (year < 1000)
year+=1900
var day=mydate.getD ay()
var month=mydate.ge tMonth()
var daym=mydate.get Date()
if (daym<10)
daym="0"+daym
var hours=mydate.ge tHours()
var minutes=mydate. getMinutes()
var seconds=mydate. getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
{
d = new Date();
Time24H = new Date();
Time24H.setTime (d.getTime() + (d.getTimezoneO ffset()*60000) +
3600000);
InternetTime = Math.round((Tim e24H.getHours() *60+Time24H.get Minutes())
/ 1.44);
if (InternetTime < 10) InternetTime = '00'+InternetTi me;
else if (InternetTime < 100) InternetTime = '0'+InternetTim e;
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+min utes
if (seconds<=9)
seconds="0"+sec onds
//change font size here
var cdate=dayarray[day]+", "+montharra y[month]+" "+daym+" "+year+" |
"+hours+":"+min utes+" "+dn+" "
if (document.all)
document.all.cl ock.innerHTML=c date
else if (document.getEl ementById)
document.getEle mentById("clock ").innerHTML=cd ate
else
document.write( cdate)
}
if (!document.all& &!document.getE lementById)
getthedate()
function goforit(){
if (document.all|| document.getEle mentById)
setInterval("ge tthedate()",100 0)
}
window.onload=g oforit
// End -->
And the 2nd script - ****Countdown until given date*****
function setcountdown(th eyear,themonth, theday){
yr=theyear;mo=t hemonth;da=thed ay
}
//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////
//STEP 1: Configure the countdown-to date, in the format year, month,
day:
setcountdown(20 04,12,25)
//STEP 2: Change the two text below to reflect the occasion, and
message to display on that occasion, respectively
var occasion="Chris tmas!"
var message_on_occa sion="Merry Christmas!"
//STEP 3: Configure the below 5 variables to set the width, height,
background color, and text style of the countdown area
var countdownwidth= '480px'
var countdownheight ='20px'
var countdownbgcolo r='white'
var opentags='<font face="Arial" size="4" color="red"><sm all>'
var closetags='</small></font>'
//////////DO NOT EDIT PASS THIS LINE//////////////////
var montharray=new Array("Jan","Fe b","Mar","Apr", "May","Jun","Ju l","Aug","Sep", "Oct","Nov","De c")
var crosscount=''
function start_countdown (){
if (document.layer s)
document.countd ownnsmain.visib ility="show"
else if (document.all|| document.getEle mentById)
crosscount=docu ment.getElement ById&&!document .all?document.g etElementById(" countdownie")
: countdownie
countdown()
}
if (document.all|| document.getEle mentById)
document.write( '<span id="countdownie "
style="width:'+ countdownwidth+ ';
background-color:'+countdo wnbgcolor+'"></span>')
window.onload=s tart_countdown
function countdown(){
var today=new Date()
var todayy=today.ge tYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.ge tMonth()
var todayd=today.ge tDate()
var todayh=today.ge tHours()
var todaymin=today. getMinutes()
var todaysec=today. getSeconds()
var todaystring=mon tharray[todaym]+" "+todayd+", "+todayy+"
"+todayh+":"+to daymin+":"+toda ysec
futurestring=mo ntharray[mo-1]+" "+da+", "+yr
dd=Date.parse(f uturestring)-Date.parse(toda ystring)
dday=Math.floor (dd/(60*60*1000*24) *1)
dhour=Math.floo r((dd%(60*60*10 00*24))/(60*60*1000)*1)
dmin=Math.floor (((dd%(60*60*10 00*24))%(60*60* 1000))/(60*1000)*1)
dsec=Math.floor ((((dd%(60*60*1 000*24))%(60*60 *1000))%(60*100 0))/1000*1)
//if on day of occasion
if(dday<=0&&dho ur<=0&&dmin<=0& &dsec<=1&&today d==da){
if (document.layer s){
document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+me ssage_on_occasi on+closetags)
document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
}
else if (document.all|| document.getEle mentById)
crosscount.inne rHTML=opentags+ message_on_occa sion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layer s){
document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+"O ccasion
already passed! "+closetags )
document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
}
else if (document.all|| document.getEle mentById)
crosscount.inne rHTML=opentags+ "Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layer s){
document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+dd ay+
" days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left
until "+occasion+clos etags)
document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
}
else if (document.all|| document.getEle mentById)
crosscount.inne rHTML=opentags+ dday+ " days, "+dhour+" hours, "+dmin+"
minutes, and "+dsec+" seconds left until "+occasion+clos etags
}
setTimeout("cou ntdown()",1000)
}
is a time/date script, the other is a countdown script (i.e. countdown
days, hours, mins until a given date). They both work independent of
each other, however, when both are on the page, the "active clock"
does not work. I am assuming it is because some of the variables are
the same???
Can anyone help please?!?!
Here are the 2 scripts:
**Active Clock that displays current time/date info**
<!-- Begin
var dayarray=new Array("Sunday", "Monday","Tuesd ay","Wednesday" ,"Thursday","Fr iday","Saturday ")
var montharray=new Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se ptember","Octob er","November", "December")
function getthedate(){
var mydate=new Date()
var year=mydate.get Year()
if (year < 1000)
year+=1900
var day=mydate.getD ay()
var month=mydate.ge tMonth()
var daym=mydate.get Date()
if (daym<10)
daym="0"+daym
var hours=mydate.ge tHours()
var minutes=mydate. getMinutes()
var seconds=mydate. getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
{
d = new Date();
Time24H = new Date();
Time24H.setTime (d.getTime() + (d.getTimezoneO ffset()*60000) +
3600000);
InternetTime = Math.round((Tim e24H.getHours() *60+Time24H.get Minutes())
/ 1.44);
if (InternetTime < 10) InternetTime = '00'+InternetTi me;
else if (InternetTime < 100) InternetTime = '0'+InternetTim e;
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+min utes
if (seconds<=9)
seconds="0"+sec onds
//change font size here
var cdate=dayarray[day]+", "+montharra y[month]+" "+daym+" "+year+" |
"+hours+":"+min utes+" "+dn+" "
if (document.all)
document.all.cl ock.innerHTML=c date
else if (document.getEl ementById)
document.getEle mentById("clock ").innerHTML=cd ate
else
document.write( cdate)
}
if (!document.all& &!document.getE lementById)
getthedate()
function goforit(){
if (document.all|| document.getEle mentById)
setInterval("ge tthedate()",100 0)
}
window.onload=g oforit
// End -->
And the 2nd script - ****Countdown until given date*****
function setcountdown(th eyear,themonth, theday){
yr=theyear;mo=t hemonth;da=thed ay
}
//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////
//STEP 1: Configure the countdown-to date, in the format year, month,
day:
setcountdown(20 04,12,25)
//STEP 2: Change the two text below to reflect the occasion, and
message to display on that occasion, respectively
var occasion="Chris tmas!"
var message_on_occa sion="Merry Christmas!"
//STEP 3: Configure the below 5 variables to set the width, height,
background color, and text style of the countdown area
var countdownwidth= '480px'
var countdownheight ='20px'
var countdownbgcolo r='white'
var opentags='<font face="Arial" size="4" color="red"><sm all>'
var closetags='</small></font>'
//////////DO NOT EDIT PASS THIS LINE//////////////////
var montharray=new Array("Jan","Fe b","Mar","Apr", "May","Jun","Ju l","Aug","Sep", "Oct","Nov","De c")
var crosscount=''
function start_countdown (){
if (document.layer s)
document.countd ownnsmain.visib ility="show"
else if (document.all|| document.getEle mentById)
crosscount=docu ment.getElement ById&&!document .all?document.g etElementById(" countdownie")
: countdownie
countdown()
}
if (document.all|| document.getEle mentById)
document.write( '<span id="countdownie "
style="width:'+ countdownwidth+ ';
background-color:'+countdo wnbgcolor+'"></span>')
window.onload=s tart_countdown
function countdown(){
var today=new Date()
var todayy=today.ge tYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.ge tMonth()
var todayd=today.ge tDate()
var todayh=today.ge tHours()
var todaymin=today. getMinutes()
var todaysec=today. getSeconds()
var todaystring=mon tharray[todaym]+" "+todayd+", "+todayy+"
"+todayh+":"+to daymin+":"+toda ysec
futurestring=mo ntharray[mo-1]+" "+da+", "+yr
dd=Date.parse(f uturestring)-Date.parse(toda ystring)
dday=Math.floor (dd/(60*60*1000*24) *1)
dhour=Math.floo r((dd%(60*60*10 00*24))/(60*60*1000)*1)
dmin=Math.floor (((dd%(60*60*10 00*24))%(60*60* 1000))/(60*1000)*1)
dsec=Math.floor ((((dd%(60*60*1 000*24))%(60*60 *1000))%(60*100 0))/1000*1)
//if on day of occasion
if(dday<=0&&dho ur<=0&&dmin<=0& &dsec<=1&&today d==da){
if (document.layer s){
document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+me ssage_on_occasi on+closetags)
document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
}
else if (document.all|| document.getEle mentById)
crosscount.inne rHTML=opentags+ message_on_occa sion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layer s){
document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+"O ccasion
already passed! "+closetags )
document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
}
else if (document.all|| document.getEle mentById)
crosscount.inne rHTML=opentags+ "Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layer s){
document.countd ownnsmain.docum ent.countdownns sub.document.wr ite(opentags+dd ay+
" days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left
until "+occasion+clos etags)
document.countd ownnsmain.docum ent.countdownns sub.document.cl ose()
}
else if (document.all|| document.getEle mentById)
crosscount.inne rHTML=opentags+ dday+ " days, "+dhour+" hours, "+dmin+"
minutes, and "+dsec+" seconds left until "+occasion+clos etags
}
setTimeout("cou ntdown()",1000)
}
Comment