Current location: Hot Scripts Forums » General Web Coding » JavaScript » Problem creating a countdown table


Problem creating a countdown table

Reply
  #1 (permalink)  
Old 01-08-04, 08:17 PM
Req Req is offline
New Member
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Problem creating a countdown table

I'm trying to create a countdown table.

Here is the code that I'm using for it.

My Field 3 and Field 4 are working however, Field 2 reads NaN instead of the number of days left.

Could someone take a look and advise something

(also.. I'm a moron at JavaScript.. my boss asked me to do this.. so when you reply could you dumb it down a bit ).

Cheers
- Req

<script Language="JavaScript">
var timerID = null;
var timerRunning = false;
var date1 = "April 2nd, 2004"
var date2 = "May 28th, 2004"
function stopclock ()
{
if(timerRunning) clearTimeout(timerID);
timerRunning = false;
}

function startclock ()
{
// Make sure the clock is stopped
stopclock();
showtime();
}

function showtime ()
{
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();

var date = now.getDate();
var month = now.getMonth() + 1;
var year = now.getYear();
if (year < 1000) year+=1900

var timeValue = "" + ((hours < 10 ) ? "0" : "") + hours
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds

document.clock.face.value = timeValue + " " + date + "/" + month + "/" + year;

nextDate = new Date(date1)
msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day

daysLeft = (nextDate.getTime() - now.getTime()) / msPerDay;
daysLeft = Math.round(daysLeft);
document.Frame2.Date1.value = daysLeft + " days until Alpha - " + date1;

nextDate = new Date(date2)
msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day

daysLeft = (nextDate.getTime() - now.getTime()) / msPerDay;
daysLeft = Math.round(daysLeft);
document.Frame3.Date2.value = daysLeft + " days until Final - " + date2;

daysLeft = (nextDate.getTime() - now.getTime()) / 1000;//msPerDay;
daysLeft = Math.round(daysLeft);
document.Frame4.Date3.value = daysLeft + " seconds until Final Submission";

timerID = setTimeout("showtime()",1000);

timerRunning = true;
}
</script>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
auto table resize derick_2k JavaScript 4 04-26-04 02:32 PM
MySQL table problem perleo PHP 9 12-16-03 01:16 PM
table create problem spinicrus PHP 1 11-17-03 04:17 AM
Dataset problem: table permissions? petersza ASP.NET 0 10-15-03 10:59 AM
moving data from table to table ..please help! geneane ASP 2 09-22-03 07:02 PM


All times are GMT -5. The time now is 11:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.