Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2004, 06:27 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date validation

function doDateCheck(FchIni, FchFin)
{
if (Date.parse(FchIni.value) <= Date.parse(FchFin.value))
{
alert("The dates are valid.");
}

How do I make it so if FchIni is < todays date an alert will fire? Is there an equivalent like the data() function in VB?

Reply With Quote
  #2 (permalink)  
Old February 9th, 2004, 06:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Code:
var dt = new Date(); //get the date

var day = dt.getDate(); //get the day

var month = dt.getMonth(); //get the month

var year = dt.getYear(); //get the year

//---------------------
//From here you will have some fancy comparisons between the saved date and the current date
//---------------------

//Example:

if(year >= old_year && month >= old_month && day >= old_date)alert("WHATEVER");
HOWEVER, the above comparison will not work. You will probably end up with a few ifs, and I seem to remember something about JavaScript's month being one behind, so January is 0, February is 1, etc.

Let me know if you need a better explanation.

HTH,

----------
---Snib---
----------
Reply With Quote
  #3 (permalink)  
Old February 9th, 2004, 07:20 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think this works. I didnt know you had to instantiate the date first.
var dt = new Date();
if (Date.parse(FchIni.value) <= dt)
       {
        alert("Message");
        form.FchIni.focus();
        return(false);
    }

Reply With Quote
  #4 (permalink)  
Old February 25th, 2004, 03:10 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

function doDateCheck(FchIni, FchFin, mydt)
{
    var dt = new Date();
    if (Date.parse(FchIni.value) >= Date.parse(FchFin.value))
    {
    alert("Start date can't be greater than end date.");
    return false;
    }
    if (Date.parse(FchIni.value) < dt)
    {
    alert("Start Date must be equal or greater than todays date" + dt);
    return false;
    }
}

When the user inputs todays date it still fires the alert. I think it has something to do with the time being included. Is there a way to cut out the time or a work around.

Reply With Quote
  #5 (permalink)  
Old February 25th, 2004, 04:04 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it to work thanks!

var today = new Date()
    var day = today.getDate()
    var month = today.getMonth()+1
    var year = today.getFullYear()
    var s = "/"
    var mydate = day + s + month + s + year

    if (Date.parse(FchIni.value) >= Date.parse(FchFin.value))
    {
    alert("Start Date must be equal or greater than todays date
    return false;
    }
    if (form.FchIni.value < mydate)
    {
    alert("%#%/!");
    return false;
    }
}

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Validation aftabn10 PHP How-To 0 January 29th, 2007 10:35 AM
Date validation vacak Struts 0 November 21st, 2006 12:11 PM
Date Validation ramesh055 ASP.NET 1.0 and 1.1 Professional 1 November 15th, 2006 11:09 AM
date validation (again) crmpicco Javascript How-To 14 March 29th, 2006 06:58 PM
Date Validation surendran Javascript How-To 3 February 25th, 2005 07:40 AM



All times are GMT -4. The time now is 12:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.