How do I make this countdown echo on screen?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4434
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I make this countdown echo on screen?

Post by simonmlewis »

Code: Select all

//change the text below to reflect your own,
var before="Christmas Day!"
var current="It's Christmas Day!!"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy
var futurestring=montharray[m-1]+" "+d+", "+yr
var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
if (difference==0)
document.write(current)
else if (difference>0)
document.write("The Christmas Countdown Starts Here!  Only "+difference+" days to go...")
}
//enter the count down date using the format year/month/day
countdown(2015,12,25)
I've got this countdown script we used last year, and we want to use it again, but I don't recall how I made it appear on screen.

I have tried this:

Code: Select all

<script src="/js/xmas.js"></script>
But nothing shows,
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I make this countdown echo on screen?

Post by Celauran »

Did you try updating the date to 2016?
simonmlewis
DevNet Master
Posts: 4434
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I make this countdown echo on screen?

Post by simonmlewis »

Code: Select all

//change the text below to reflect your own,
var before="Christmas Day!"
var current="It's Christmas Day!!"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy
var futurestring=montharray[m-1]+" "+d+", "+yr
var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
if (difference==0)
document.write(current)
else if (difference>0)
document.write("The Christmas Countdown Starts Here!  Only "+difference+" days to go...")
}
//enter the count down date using the format year/month/day
countdown(2016,12,25)
Yes just tried this. I was assuming just adding the js code on the page would do it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I make this countdown echo on screen?

Post by Celauran »

So it's sorted?
simonmlewis
DevNet Master
Posts: 4434
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I make this countdown echo on screen?

Post by simonmlewis »

No. It's not producing anything on screen.
If you do a dummy page, with that code, in theory it should show... should it not?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do I make this countdown echo on screen?

Post by Celauran »

I did, and it does.
simonmlewis
DevNet Master
Posts: 4434
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I make this countdown echo on screen?

Post by simonmlewis »

How?? Exactly as I did. that's bizarre.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply