473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Date Validation - Disallow Past Dates

Hi Everyone,

I've got a form that provides a pop-up calendar for users to select
dates for requesting jobs to be completed. The calendar works great,
but it unfortunately allows users to select dates earlier than today
(which they should't be allowed to do). I've started coding some
validation scripts, but I'm stuck now and my approach doesn't seem to be
working.

I've Googled all morning looking for an answer and couldn't find one and
I searched the newsgroups as well. Below is my code:

<html>
<script language="JavaScript" type="text/javascript">
<!--
var now = new Date(); // Create a new Date Object
var day = now.getDay(); // day returns integer of 0-6 which will be
stored in the variable day
var month = now.getMonth(); // month returns integer of 0-11 which will
be stored in the variable month
var date = now.getDate(); // day returns integer of 1-31 which will be
stored in the variable date
var year = now.getYear();
if (year < 2000) year += 1900

var tom = new Date("December 9, 2003");
var newday = tom.getDay();
var newmonth = tom.getMonth();
var newyear = tom.getYear();

document.write("Now is <b>" + now + "<br>");
document.write("Today is: <b>" + month+date+year + "<br>");
document.write("Today is: <b>" + month + "/" + date + "/" + year +
"</b><br>");
document.write("Var date is <b>" + tom + "<br>");
document.write("Var day is <b> " + newday + "<br>");
document.write("Var month is <b> " + newmonth + "<br>");
document.write("Var year is <b> " + newyear + "<br>");
-->
</script>

<form method="post" name="data" onSubmit="return isitToday()">
<input type="text" name= "mydate">
<input type="submit" value="Check">
</form>

</html>
Thanks!

Jul 20 '05 #1
4 11664
"Dale" <Da**@somewhere.com> wrote:
I've got a form that provides a pop-up calendar for users to select
dates for requesting jobs to be completed. The calendar works great,
but it unfortunately allows users to select dates earlier than today
(which they should't be allowed to do).


I've got a popup calendar which will allow you to disable past dates:
http://www.mattkruse.com/javascript/calendarpopup/

And I've also get general date routines which will allow you to check and
validate dates and such:
http://www.mattkruse.com/javascript/date/

Hope that helps!

Matt
Jul 20 '05 #2
Matt Kruse wrote:

I've got a popup calendar which will allow you to disable past dates:
http://www.mattkruse.com/javascript/calendarpopup/

Thanks Matt! I sent you an email off-line.

Dale

Jul 20 '05 #3
JRS: In article <QV*********************@news.easynews.com>, seen in
news:comp.lang.javascript, Dale <Da**@somewhere.com> posted at Wed, 10
Dec 2003 21:06:56 :-
I've got a form that provides a pop-up calendar for users to select
dates for requesting jobs to be completed. The calendar works great,
but it unfortunately allows users to select dates earlier than today
(which they should't be allowed to do). I've started coding some
validation scripts, but I'm stuck now and my approach doesn't seem to be
working.

I've Googled all morning looking for an answer and couldn't find one and
I searched the newsgroups as well.
Did you not find the FAQ of this newsgroup sufficiently helpful? If you
did not, why not?

var now = new Date(); // Create a new Date Object var tom = new Date("December 9, 2003");


I assume that you wish to compare now with tom and that tom should be in
the future from 0000h today local time. The necessary test is shown by

if (tom < now.setHours(0,0,0,0)) alert("twirly")
Validation : <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> Jsc maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.
Jul 20 '05 #4
Dr John Stockton wrote:

Did you not find the FAQ of this newsgroup sufficiently helpful? If you
did not, why not?
I missed seeing the FAQ in my search attempts.

I assume that you wish to compare now with tom and that tom should be in
the future from 0000h today local time. The necessary test is shown by

if (tom < now.setHours(0,0,0,0)) alert("twirly")
Validation : <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.


Thanks!

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
14
by: Steve Wright | last post by:
I am trying to validate if an entry on a form is a date. I have adapted code I found here http://www.codingforums.com/archive/index.php/t-14325 as below but I can't seem the get the results that I...
3
by: LDD | last post by:
Are there any built in time and/or date validation methods that one can make use of in .NET? thanks folks LDD
3
by: pmarisole | last post by:
The following javascript code gives me the date validation that I need except after the correct date is entered into the field, it puts the date in the wrong format EXAMPLE: User enters...
1
by: Greg Smith | last post by:
Is there a way to disable past dates for a calendar control, or individual date for that matter? Any help is greatly appreciated.
2
by: John Smith | last post by:
Hello, I have a VB.NET application with a Windows form that have several textboxes fields where I have dates entered. I would like to do a date validation check after the the field is updated, so...
5
Stang02GT
by: Stang02GT | last post by:
I have been asked to validate a date on our web-page so that people cannot enter dates like 14/1/08 or 2/30/06. I have found code that will do exactly what i need it to do, but i am not sure how to...
2
by: mshroom12 | last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete. Date Validation In this exercise you will write a program...
11
by: fran7 | last post by:
Hi, I wonder if anyone can help. I have a query like this <% If datediff("d", , now()) < 21 Then %> <a target=_blank title="blog" href="news</a> <% Else %>
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.