ravi_raj123
asked on
Compare two date - text boxes
Hi,
In my form I have checkin and checkout text boxes, user enters the dates in dd/mm/yyyy format, how do I compare these two dates? I have to give alert if the checkout date is before the checkin date. Please help.
Cheers :)
In my form I have checkin and checkout text boxes, user enters the dates in dd/mm/yyyy format, how do I compare these two dates? I have to give alert if the checkout date is before the checkin date. Please help.
Cheers :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops the one i posted checks and validates against todays date which is not ur requirement.. ignore it pls..
ASKER
Idbkutty thanks for your solution. I did exactly what you answered but before you answered. But I will give accept your answer.
Archrajan thanks for your effort :)
Archrajan thanks for your effort :)
<html>
<head>
<script>
function checkForm(theForm){
fDate = new Date(theForm.fromDate.valu
if(isNaN(fDate)){
alert("Please eneter FromDate.\nFormat: MM/DD/YYYY");
theForm.fromDate.focus();
return false;
}
if((fDate.getTime()+864000
alert("FromDate is in the past.");
theForm.fromDate.select();
theForm.fromDate.focus();
return false;
}
tDate = new Date(theForm.toDate.value)
if(isNaN(tDate)){
alert("Please eneter ToDate.\nFormat: MM/DD/YYYY");
theForm.toDate.focus();
return false;
}
if(tDate < fDate){
alert("FromDate is greater the ToDate.");
theForm.fromDate.select();
theForm.fromDate.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form onSubmit="return checkForm(this)">
From:
<input type=text name="fromDate">
To:
<input type=text name="toDate">
<input type=submit>
</form>
</body>
</html>