Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code which is not working...
any suggestions


C#
var datefrom = $('#<%=txtVisitDateFrom.ClientID%>').val();
           var dateTo = $('#<%=txtVisitDateTo.ClientID%>').val();

           if (Date.parse(datefrom) > Date.parse(dateTo)) {
               alert('Date from should not be greater than date to');
               return false;
           }
Posted

I suggest using datepicker[^]
from JQuery UI plugin, see example:
XML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script>
    $(document).ready(function () {
        $('#dateFrom').datepicker();
        $('#dateTo').datepicker({
            onSelect: function () {
                var dateFrom = $('#dateFrom').datepicker('getDate');
                var dateTo = $(this).datepicker('getDate');
                if (dateFrom >= dateTo) {
                    alert("Oop! dateTo must be later than dateFrom.");
                }
            }
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        From <asp:TextBox ID="dateFrom" runat="server"></asp:TextBox>
        To <asp:TextBox ID="dateTo" runat="server"></asp:TextBox>
    </div>
    </form>
 
Share this answer
 
Comments
manish bhatt 23-Jan-15 23:32pm    
thanks... Its working perfectly...
Hello ,
First check datefrom and dateto in your code . after that try
if(new Date(datefrom) > new Date(dateto))
{
 //other stuff
 
}

thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900