hi all,
I have a form where the user clicks on a little calendar image and a calendar pops up...they select the date and it gets placed into the field.
then, i need to make sure that they have not selected a date AFTER today's date...so here is the code I used:
var today = new Date();
today = (padout(today.getMonth()+1)) + "/" + padout(today.getDate()) + "/" + padout(today.getFullYear());
if (document.claims.DateofLoss.value > today)
{
alert ("Please select a date before today's date!");
return false;
}
This partially works...if I select any date in 2005 that is after today's date, it gives me the message and works...if I select any date in 2005 before today's date, it works fine and lets me through...
HOWEVER, if I select a date BEFORE today's date but in 2004 or before, it gives me the message again that "Please select a date before today's date!"....!?!? why?
Try creating functions that test the input year etc to the current then if all of those return true then let them through otherwise alert.
ex
function checkYear(form, today){
if(form < today)
return true
}
// each funtion checks to see if each is less than the other and returns a boolean
yearOK = checkYear(formYear, todaysYear);
monthOK = checkMonth(formMonth, todaysMonth);
dayOK = checkDay(formDay, todaysDay);
these functions dont work in the correct manor but they give you an idea of another method of checking. more round about but it works as long as your logic is ok.
hey stereofrog,
im trying to implement wat you said...it makes sense...turn the date into a number (milliseconds from epoch) and then compare numbers....right?
i cant seem to figure it out though! i've been trying to use the date.parse function but can't seem to make it work.
var difference = 0;
inputdate = new Date(document.claims.DateofLoss.value);
today = new Date();
difference = today - inputdate;
if (difference < 0)
{
alert ("Please select a date before today's date!");
return false;
}
it worked....please let me know if anyone sees a problem with this that i am not seeing.
Bookmarks