In my ASP web page, I am utilizing an AJAX calendar to allow users to select a date. I want to restrict users from selecting past dates, current date, or dates more than 20 days in the future.
var today = new Date();
var twentyDays = new Date();
twentyDays.setDate(today.getDate() + 20);
if (selectedDate.getDateOnly() <= todayDate.getDateOnly())
{
alert('Please choose a date in the future.');
sender._textbox.set_Value(null);
}
else if (selectedDate.getDateOnly() > twentyDays.getDateOnly())
{
alert('Selected date should not exceed 20 days into the future');
sender._textbox.set_Value(null);
return;
}
However, it seems that the code is not properly comparing the selected date against the restrictions mentioned above.
<asp:TextBox ID="txtDate" runat="server" ></asp:TextBox>
<asp:ImageButton ID="imgCalender" runat="server" ImageUrl="~/Images/Calendar.png" ToolTip="Select a Date" />
<asp:CalendarExtender ID="calShow" runat="server" PopupButtonID="imgCalender" PopupPosition="BottomLeft" TargetControlID="txtDate" OnClientDateSelectionChanged="CheckForPastDate"></asp:CalendarExtender>