View Single Post
  #1   Spotlight this post!  
Unread 29-03-2004, 00:15
steveg's Avatar
steveg steveg is offline
Livin' the Dream
AKA: Stephen Guerrera
no team
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Boston, MA
Posts: 70
steveg is a splendid one to beholdsteveg is a splendid one to beholdsteveg is a splendid one to beholdsteveg is a splendid one to beholdsteveg is a splendid one to beholdsteveg is a splendid one to beholdsteveg is a splendid one to beholdsteveg is a splendid one to behold
Send a message via AIM to steveg
javascript ate my cereal!

I'm trying to code a simple countdown timer for a friend, but the code as it is now will run once, then return NaNs for the numbers. Eventually it will start working under safari, but not under IE or Mozilla. Any suggestions?

Code:
<FORM name=count>
	<INPUT size=73 name=count2>
</FORM>

<SCRIPT>

//Count down until any date and time


var until='Party'
var current='A Title of some sort to display when time is up'
var montharray=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')

function countdown(yr,mth,day,hour,min,sec)
{
	theyear=yr;themonth=mth;theday=day;thehr=hour;themin=min;thesec=sec
	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[mth-1]+' '+theday+', '+theyear+' '+thehr+':'+themin+':'+thesec
	

	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(dday==0&&dhour==0&&dmin==0&&dsec==0)
	{
		document.forms.count.count2.value=current
		return
	}
	else
		document.forms.count.count2.value='Only '+dday+ ' days, '+dhour+' hours, '+dmin+' minutes, and '+dsec+' seconds left until '+until

	setTimeout('countdown(theyear,themonth,theday,themin,thesec)',1000)
}
//enter the count down date using the format year/month/day/hour/minute/seconds

countdown(2004,4,15,0,0,0)

</SCRIPT>