Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2004, 09:27 AM
Authorized User
 
Join Date: Oct 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble with date method...

I'm having a bit of trouble with the date method. What I'm trying to do is write some script that counts down to 5pm on the current day. If you can take a look at it and let me know what I'm doing wrong, that would be great. Thanks!

Code:
<html>
<title>OH MY GOD! When Will it end!?!?!</title>
<head>
<script LANGUAGE="JavaScript">
<!--

var now = new Date();
var seconds = 60 - getSeconds();
var minutes = 60 - getMinutes();
var hours = 17 - getHours();
ID=window.setTimeout("update();", 1000);

function update() {
now = new Date();
seconds = 60 - getSeconds();
seconds = Math.round(seconds);
minutes = 60 - getMinutes();
minutes = Math.round(minutes);
hours = 17 - getHours();
hours = Math.round(hours);
document.form1.hours.value = hours;
document.form1.minutes.value = minutes;
document.form1.seconds.value = seconds;
ID=window.setTimeout("update();",1000);
}
// --></script>
</head>
<body bgcolor=blue>

<p>Countdown To 5:00 pm today: </p>
<form name="form1"><p>

 Hours 
<input type="text" name="hours" value="0" size="4"> Minutes <input type="text" name="minutes" value="0"
size="7"> Seconds <input type="text" name="seconds" value="0" size="7"> </p>
</form>

</body>
</html>
 
Old May 25th, 2004, 09:52 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Are you getting any errors?

Also, I don't think you can just call functions like getSeconds(). Such functions are methods specific to Date() values.

Try replacing getMinutes() with now.getMinutes() and same with getSeconds() and getHours().

HTH,

Snib

<><
 
Old May 25th, 2004, 10:04 AM
Authorized User
 
Join Date: Oct 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That was it! It wasn't working because I didn't have now.get~ . Thanks Snib!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Best method to store date & Time with SQL 2000 harini19 Java Basics 0 February 15th, 2006 12:52 AM
OnCheckedChanged trouble with codebehind method theycallmetish General .NET 1 July 9th, 2005 01:33 PM
Trouble with date formats DrewMills Access VBA 3 March 7th, 2005 06:22 PM
Trouble with comparing date fields JimmyNeutron Access VBA 3 February 22nd, 2005 09:14 AM
Date trouble using Dreamweaver Update Dirosky Dreamweaver (all versions) 2 January 8th, 2004 09:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.