PDA

View Full Version : Countdown code doesn't work



jordan
09-23-2004, 05:42 PM
At the following site on this server http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm there is a count down code that I am trying to use on my website. It works once then doesn't work. Does it matter if the code is wrapped?

ddadmin
09-24-2004, 07:31 PM
By working only "once", do you mean you have multiple copies of the same script on the page? Please elaborate.

jordan
09-24-2004, 08:40 PM
I only have it on the page once. When I visit my site right after putting it on my page it works. When i work on my site it doesn't work. :(

gigabites
09-25-2004, 12:01 AM
What is Your site? Maybe we can see whats wrong by visiting it.

jordan
09-25-2004, 09:22 PM
www.simulationcity.bravehost.com

I'm trying to use the code to countdown the release of RollerCoaster Tycoon3.

gigabites
09-25-2004, 11:21 PM
Don't put them all in one lline...

Some parts of the script contains a "//" sign. It's a one line comment... It means that from that point on to the rest of the line is considered as a comment. :)

jordan
09-26-2004, 02:19 PM
I'm not putting it one one line. My web hoster (Bravenet) squishes it all together.So there are no spaces in-between. The only way it would work was if I put it in my forum.

gigabites
09-26-2004, 03:15 PM
Hmmm... Try to put the script in an external file then...

Cut the section betwen the <script> and </script> tags, and paste it in another a file, countdown.js for example.

Modify the script tag to

<script src="countdown.js" language="JavaScript1.2">
Will it work?

jordan
09-26-2004, 06:09 PM
I'm just going to put it in my forum I don't understand what you're saying.

gigabites
09-27-2004, 12:01 AM
OK.. first, copy this code


/*
Dynamic countdown Script- Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS,
visit http://www.dynamicdrive.com
*/


function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day:
setcountdown(2004,09,30)

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion="Christmas!"
var message_on_occasion="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 countdownbgcolor='lightblue'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}Save it as "countdown.js" and upload it to Your server. Put it in the same directory as Your forum page.

And then add this code :

<script src="countdown.js" language="JavaScript1.2"></script>
<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer> on Your forum page...

No guarantees it'll work though :(

Staffie
02-25-2011, 12:03 PM
I AM A TOTAL NOOB
weird... I have the code and thought it worked. On Chrome it's working fine but on FF and IE it goes .... will expire in NaN days, NaN hours, NaN minutes -and NaN seconds ... I have also tried the above regarding calling the .js file but it does the same. Am I just being stupid here or what ? http://www.onshuis.co.za/home.html#AGENT (bottom at terms....)
I only realised it today... Any reasons for this ?