Monday, May 23, 2011

Javascript FromDate to Date Validation

<html xmlns="">
<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.");
        return false;
    else {
        return true;
    <form id="form1" runat="server">
    <p><b>DD/MM/YEAR Format</b></P>
        From Date<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
        To Date 
        <asp:TextBox ID="txtto" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Click" OnClientClick="return CompareDate(txtfrom,txtto);" />


Post a Comment