Hiya all.
I have a form which the user selects a date from a javascript style calendar, it puts the date into a field in the format dd/mm/yyyy.
I want the form to compare this user selected date to a date which it will work out, which is today's date pluys 7 days.
The reason is, the field is a 'Required by' field on a form and I dont want the user to enter a date in the past or one which is less than 7 days from today.
So it will comare the date entered to a date 7 days from today.
I have the logic right (I think), and included it here, but for somereason a date where the day is 10th or greater seems to trips up!
Any ideas???
I have a form which the user selects a date from a javascript style calendar, it puts the date into a field in the format dd/mm/yyyy.
I want the form to compare this user selected date to a date which it will work out, which is today's date pluys 7 days.
The reason is, the field is a 'Required by' field on a form and I dont want the user to enter a date in the past or one which is less than 7 days from today.
So it will comare the date entered to a date 7 days from today.
I have the logic right (I think), and included it here, but for somereason a date where the day is 10th or greater seems to trips up!
Any ideas???
Code:
<script>
function checkadate(){
//This bit gets todays date and add seven days
var currentdate = new Date();
currentdate.setDate(currentdate.getDate()+7);
var day = currentdate.getDate();
var month = currentdate.getMonth() + 1;
var year = currentdate.getFullYear();
//This bit puts that date in to dd/mm/yyyy format
var todat = (day + "/" + month + "/" + year)
alert("Todays date plus 7 is " +todat);
//This is the date entered by the user.
var ReqDate = document.getElementById("DateRequired").value;
alert("Selected date is " + ReqDate);
var SDate = (todat);
var EDate = document.getElementById("DateRequired").value;
var endDate = new Date(EDate);
var startDate= new Date(SDate);
if(startDate > endDate){
alert("Date must be at least 5 working days in advance to allow for processing.\nThe earliest date available is " + SDate);
document.getElementById("DateRequired").value = SDate;
return false;
}else{
}
}
</script>
Comment