Go to Post So remember, no matter what the odds, your wildest dreams can come true with science and technology. - Ian Curtis [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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>
  #2   Spotlight this post!  
Unread 29-03-2004, 00:43
piotrm's Avatar
piotrm piotrm is offline
Registered User
AKA: Piotr Mardziel
FRC #0190 (Gompei and the HERD)
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2001
Location: Dudley, MA
Posts: 96
piotrm has a spectacular aura aboutpiotrm has a spectacular aura about
Send a message via AIM to piotrm
Re: javascript ate my cereal!

Quote:
Originally Posted by steveg
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?
try this (sorry I had to add spaces to this so I could actually read it):

Code:
<html>
<body>
<FORM name=count>
 <INPUT size=73 name=count2>
</FORM>
</body>
</html>
<SCRIPT language="javascript">
//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');
var theyear;
var themonth;
var theday;
var thehr;
var themin;
var thesec;
function countstart(yr, mth, day, hour, min, sec) {
  theyear  = yr;
  themonth = mth;
  theday   = day;
  thehr	= hour;
  themin   = min;
  thesec   = sec;
  setTimeout('countdown()', 1000);
}
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[themonth-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()', 1000);
}
//enter the count down date using the format year/month/day/hour/minute/seconds
countstart(2004,3,29,1,0,0);
</SCRIPT>
  #3   Spotlight this post!  
Unread 29-03-2004, 01:10
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
Re: javascript ate my cereal!

Awsome, thank you!

Though I don't know why it didn't work the way it was before.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript onclick link concatination Trashed20 Website Design/Showcase 10 04-06-2003 11:18


All times are GMT -5. The time now is 02:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi