I'm trying to compare 2 dates on a form. What is the simplest way to do this? Here's what I have so far:
<html>
<script>
function Compare() {
if (document.frmTest.startDat
e.value > document.frmTest.endDate.v
alue){
alert ("Start Date is greater");
}
if (document.frmTest.startDat
e.value < document.frmTest.endDate.v
alue){
alert ("End Date is greater");
}
if (document.frmTest.startDat
e.value == document.frmTest.endDate.v
alue){
alert ("Dates are the same");
}
}
</script>
<body>
<form name="frmTest">
Start Date: <input type="text" name="startDate" size="12">
<br>
End Date: <input type="text" name="endDate" size="12">
<a href="javascript:Compare()
;">Compare
</a>
</form>
</body>
</html>
If the user enters "8/1/2005" for the Start Date and "8/2/2005" for the End Date, the script works. But if the user enters "8/1/2005" and "11/01/2005" the script does not work.
Start Free Trial