I am very new to javascript.
I want to validate two a date range using javascript, so that my program would check startdate less than end date.
The below function only check the year, and it works fine.
[CODE]function validate()
{
var start=document.entry.datum1.value;
year = start.substr(0, 4);
month = start.substr(5, 2);
dayval = start.substr(8, 2);
var end=document.entry.datum2.value;
year1 = end.substr(0, 4);
month1 = end.substr(5, 2);
dayval1 = end.substr(8, 2);
var myDate=new Date();
myDate.setFullYear(year,month,dayval);
var today = new Date();
today.setFullYear(year1,month1,dayval1);
if (myDate> today)
{
alert(“The start date must come before the end date”);
return false
}
return true;
}
But I have write a function for checking the whole date value and it did not work.
My date is in format-
2008-10-23(yyyy-mm-dd)
[CODE]function validate()
{
var start=entry.datum1.value;
year = start.substr(0, 4);
month = start.substr(5, 2);
dayval = start.substr(8, 2);
intyear = parseInt(year, 10);
intmonth = parseInt(month, 10);
intdayval = parseInt(dayval, 10);
var end=entry.datum2.value;
year1 = end.substr(0, 4);
month1 = end.substr(5, 2);
dayval1 = end.substr(8, 2);
intyear1 = parseInt(year1, 10);
intmonth1 = parseInt(month1, 10);
intdayval1 = parseInt(dayval1, 10);
var startDate = Date.parse(intyear,intdayval,intmonth);
var endDate = Date.parse(intyear1,intdayval1,intmonth1);
if (startDate > endDate)
{
alert(“The start date must come before the end date”);
return false;
}
return true;
}
Please help