Friday, December 23, 2011

How to validate dates using Javascript


here is the javascript function compare two dates.

        function validatedates() {
            
            var objPEndDate = document.getElementById('<%=txtDate1.ClientID%>').value;
            var objCExpiryDate = document.getElementById('<%=txtDate2.ClientID%>').value;


            var PEndDate = new Date(objPEndDate);
            var CExpiryDate = new Date(objCExpiryDate);


            if (CExpiryDate > PEndDate) {
                alert("Coupon Expiry Date should be less than Promotion End Date.");
                return false;
            }
            return true;
        }




HTML code


<asp:TextBox ID="txtDate2" CssClass="ICStyle ICStyle3Width" onchange="validatedates();" runat="server" />

No comments:

Post a Comment