Monday, May 23, 2011

Javascript FromDate to Date Validation

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function CompareDate(txtfrom, txtto) {
    var From = txtfrom.value;
    var To = txtto.value;
    var strSplitFrom = From.split('/')
    var myDateFrom = new Date();
    myDateFrom.setFullYear(strSplitFrom[2], strSplitFrom[1] - 1, strSplitFrom[0]); 
    var strSplitTo = To.split('/')
    myDateTo = new Date();
    myDateTo.setFullYear(strSplitTo[2], strSplitTo[1] - 1, strSplitTo[0]); 
    if (myDateFrom > myDateTo) { 
        alert("Start date can not greater than End date.");
        txtfrom.focus(); 
        return false;
    }
    else {
        return true;
    } 
}
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p><b>DD/MM/YEAR Format</b></P>
        From Date<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
        <br/>
        To Date 
        <asp:TextBox ID="txtto" runat="server"></asp:TextBox>
        <br/>
        <asp:Button ID="Button1" runat="server" Text="Click" OnClientClick="return CompareDate(txtfrom,txtto);" />
    </div>
    </form>
</body>
</html>
 
javascript1
 
 
 

0 comments:

Post a Comment