0

How can i disable all future dates after three days from current date (Today) in AJAX control kit

 <asp:TextBox ID="txtEndDate" runat="server" class="form-control"
      required="This Field is Required" AutoComplete="off"></asp:TextBox>                                                            

        <ajaxToolkit:CalendarExtender ID="CalendarExtender2" 
    runat="server" OnClientDateSelectionChanged="checkProjectEndDate"
 TargetControlID="txtEndDate" Format="dd-MMM-yyyy"></ajaxToolkit:CalendarExtender>



<script type="text/javascript">
     function checkProjectEndDate(sender, args) {
     if (sender._selectedDate >= new Date()) {
     alert("You can not select a future date than today!");
     sender._selectedDate = new Date();
     sender._textbox.set_Value(sender._selectedDate.format(sender._format))
       }
      }
</script>

Its not allowing to select future date then today but i want something that i can select three day latter from today let me explain i want like user can not select any future dates after three days latter suppose today is 01-11-2019 so my calender's show only 03-11-2019 after 3Nov all date should not be visible

Nits Patel
  • 380
  • 3
  • 15
  • Here's an answered question about how to add days to a JavaScript date object: https://stackoverflow.com/questions/563406/add-days-to-javascript-date – jared Nov 01 '19 at 18:08
  • i use but its showing Wed Nov 06 2019 23:41:30 GMT+0530 (India Standard Time) – Nits Patel Nov 01 '19 at 18:12
  • i want like user can not select any future dates after three days latter suppose today is 01-11-2019 so my calender's show only 03-11-2019 after 3Nov all date should not be visible – Nits Patel Nov 01 '19 at 18:14
  • Looks like @Fraddy has built that logic for you in his answer – jared Nov 01 '19 at 18:16

1 Answers1

0

To select date which is greater than 3 days:

var date = new Date();
date.setDate(date.getDate() + 3);
if(selected_date > date){
   // code here
}

Edit: As per you question check below code snippet:

<script type="text/javascript">
  function checkProjectEndDate(sender, args) {

    var future_date = new Date();
    future_date.setDate(future_date.getDate() + 2);

    if (sender._selectedDate > future_date) {
      alert("You can not select a future date than today!");
      sender._selectedDate = new Date();
      sender._textbox.set_Value(sender._selectedDate.format(sender._format))
    }
  }
</script>
Fraddy
  • 331
  • 1
  • 8