Here is a date checker function.
If I have time I'll try and add a comparison function to it as well.
It's probably not the most elegant solution, but hey, it works (at least on my browser and platform of choice). If you don't decide to use it hopefully it will at lest give you some ideas.
/*checkDates written by Jaxon Johns 08/02/2002
Use it all you want , but it would be cool of you to give me credit. : )
This script checks two dates to be in the proper form of mm/dd/yyyy.
the two arguments are the two date strings you want checked.
It can easily handle more than two dates by adding more arguments and increasing the first for loop accordingly.
I don't have the time or resources to check it on every platform/browser combo, so hopefully it works on most.
N-Joi
*/
function checkDates (e,t) {
a = checkDates.arguments;
userError = 0;
/*checking to see if all the slashes are in the right place
this check is very strict in that you must enter the month and date as two digits each*/
outsideTheLoop://this is a lable for the break function in the nested for loop... see below
for (i = 0; i < 2 ; i++) {
CDarray=a
.split("/"
;
if (a.length==10&&a.indexOf("/"
==2&&a.lastIndexOf("/"
==5){
} else {
alert("The date(s) must be in the form mm/dd/yyyy"
;
userError=1;
break;
}
//now we are checking to see if all the input between the '/'s were numbers
for (j=0; j<3 ; j++) {
if (isNaN(CDarray[j])){
alert("only numeric values and the '/' character are allowed in the date field."
;
userError=1;
break outsideTheLoop;
}
}
}
if (userError==!1) {
alert("Thank you for submiting the form."
;
//put code for sending the form here
}
}
***************************************************
Here is an example of the form I used for testing it.
<form name="member" onSubmit="checkDates(document.member.effectiveDate.value, document.member.terminationDate.value);">
effective date <input name="effectiveDate" type="text" size="11" maxlength="11">
termination date <input name="terminationDate" type="text" size="11" maxlength="11">
<input name="enter" type="submit">
</form>
Hope this helps,
jaxon