var startYear = document.getElementById(yFrom);
This gave you just the control object. Sounds like you want to compare the two date value.
Try:
function DateValidation(yFrom, yTo) {
var startYear = document.getElementById(yFrom);
var endYear = document.getElementById(yTo);
if (startYear.value != '' && endYear.value != '')
{
if (endYear.value < startYear.value)
{
alert('Start date cannot be greater than end date');
return false;
}
else { return true; }
}
}
UPDATE:
For date comparison, you need to convert the textbox strings into dates.
Here:
function DateValidation(yFrom, yTo) {
var startYear = document.getElementById(yFrom);
var endYear = document.getElementById(yTo);
if (startYear.value != '' && endYear.value != '')
{
Date endDate = new Date(endYear.value);
Date startDate = new Date(startYear.value);
if (endDate < startDate)
{
alert('Start date cannot be greater than end date');
return false;
}
else { return true; }
}
}
Make sure that the textbox has a valid Javascript date or else you will get an error.