Thursday, 12 April 2012

Start Date Greater Than End Date Validation in Jquery

 
function ValidateDate(CtrlSDate,CtrlEDate)
    {
    var SDate = document.getElementById(CtrlSDate).value;     
    var EDate =  document.getElementById(CtrlEDate).value;
       
          
    var alertReason1 =  'End Date must be greater than or equal to  Start Date.' 
    var alertReason2 =  'End Date can not be less than Current Date.';
 
    var endDate = new Date(EDate);     
    var startDate= new Date(SDate);
     
       if(SDate != '' && EDate != '' && startDate > endDate)
    {
     alert(alertReason1);
     document.getElementById(CtrlEDate).value = "";
     return false;
    }
    else if(SDate == '') 
    {
        alert("Please enter Start Date");
        return false;
    }
else if(EDate == '') 
    {
        alert("Please enter End Date");
        return false;
    }     
}

No comments:

Post a Comment