By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,261 Members | 2,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,261 IT Pros & Developers. It's quick & easy.

Date Validation - Disallow Past Dates

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.