Thursday 16 August 2012

validation for start date should not be less than system date and end date should be greater than start date in java script

Write the code in .aspx source file within the head tag


<script type="text/javascript">
       function ChkDate(sender, arg) {
           var selectedDate = new Date();
           selectedDate = sender._selectedDate;
           var todayDate = new Date();
           var txtDate1 = document.getElementById('txtStartDatePop').value;
           var tostartDate = new Date(txtDate1);
           if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {
               sender._selectedDate = todayDate;
               sender._textbox.set_Value(sender._selectedDate.format(sender._format));
               alert("Start Date should not be less than Current Date.");
           }
       }
       function CheckStartDate(sender, args) {
           var txtDate1 = document.getElementById('txtStartDatePop').value;          
           var tostartDate = new Date(txtDate1);         
           var enddateDate = new Date(sender._selectedDate);       
           if (txtDate1.length > 0) {            
               if (enddateDate < tostartDate) {                
                   sender._selectedDate = tostartDate;               
                   sender._textbox.set_Value(sender._selectedDate.format(sender._format));                
                   alert("End Date must greater then or Equal start date");                 
               }              
           }
       }
</script>

Then after write the statement in calender extender controls
1.OnClientDateSelectionChanged="ChkDate"
2.OnClientDateSelectionChanged=" CheckStartDate "

enjoy the coading

No comments: