Date Validation - Disallow Past Dates

D

Dale

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!
 
M

Matt Kruse

Dale said:
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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
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>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top