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 August 27th, 2006, 01:35 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Date comparison problem

Good day. I am having trouble with:

if(document.assessAdmin.warningDate.value > periodFinishDate)
{
alert("Your 'Warning Date' value(" + document.assessAdmin.warningDate.value +") must be less than the end date of the current period(" + periodFinishDate + ") ");
document.assessAdmin.warningDate.focus();
document.assessAdmin.warningDate.select();
return(false);
}

The condition does not get entered in to. I have been looking at it for far to long. It does not error. I placed the alert outside the condition to see the values, they are:

document.assessAdmin.warningDate.value = 27/10/2006
periodFinishDate = 30/9/2006

FYI: the periodFinishDate value gets passed during form validation inside an event in an image tag. When I view the page source the function shows the following values (they are the start and the end dates of the current FY quarter):

onClick="return val('1/7/2006','30/9/2006');"

My objective is to not allow the form to submit if the user defined warning date is > than the last day of the current FY quarter.

TYIA

Wind is your friend
Matt
__________________
Wind is your friend
Matt
 
Old August 28th, 2006, 03:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your code has no idea that document.assessAdmin.warningDate.value is meant to be interpreted as a date. You need to convert it to one using Date.parse or using new Date(year, month, day).

--

Joe (Microsoft MVP - XML)
 
Old August 28th, 2006, 07:21 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I have failed using date.parse - I will try this new date method, thaning you...

Wind is your friend
Matt
 
Old August 30th, 2006, 09:22 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Solution:
function val(periodStartDate,periodFinishDate)
{
var AUwarningDate = document.assessAdmin.warningDate.value;
var AUWarningDateParts = AUwarningDate.split("/");
var AUWarningD = AUWarningDateParts[0];
var AUWarningM = AUWarningDateParts[1];
var AUWarningY = AUWarningDateParts[2];
var USWarningDate = new Date(AUWarningM + "/" + AUWarningD + "/" + AUWarningY);

var AUPeriodFinish = periodFinishDate;
var AUPeriodFinishParts = AUPeriodFinish.split("/");
var AUPeriodFD = AUPeriodFinishParts[0];
var AUPeriodFM = AUPeriodFinishParts[1];
var AUPeriodFY = AUPeriodFinishParts[2];
var USPeriodFinish = new Date(AUPeriodFM + "/" + AUPeriodFD + "/" + AUPeriodFY)

if(USWarningDate > USPeriodFinish)
{
   alert("Your 'Warning Date' (" + AUwarningDate +") value must be less than the finish of the current period (" + AUPeriodFinish + ").");
           return(false);
}
return(true);
}

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Comparison jroxit Classic ASP Databases 5 October 5th, 2007 05:39 PM
Access Form problem, date comparison jackson_jl VB Databases Basics 0 March 9th, 2005 02:13 PM
Date comparison lily611 General .NET 5 January 4th, 2005 07:08 AM
Date Comparison hoffmann Classic ASP Databases 7 October 21st, 2004 09:00 AM
Date Comparison cmiller PHP How-To 3 June 19th, 2003 02:58 PM





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