I'm currently using an ajax calendar extender along with JavaScript to prevent users from selecting past dates. However, I'm encountering a problem:
- When the user selects a past date, it works correctly
- If the user chooses a future date, it also works fine
However, if the user selects the current date, they still receive an alert, which is unnecessary.
My objective is to allow users to select the current date and future dates, but prohibit them from entering any prior dates. Can someone assist me in resolving this issue? Below is the code snippet for reference:
<div id="formload" >
<!-- ============================== Fieldset 1 ============================== -->
<fieldset>
<legend>Enter Date</legend>
<table>
<tr>
<td><label for="input-one" class="float"><strong>Date</strong></label>
</td><br />
<td><asp:TextBox ID="txtDate" runat="server" CssClass="inp-text" Width="300px"></asp:TextBox> </td>
<td><asp:Image runat="server" ID="btnDate2" AlternateText="cal2" ImageUrl="~/App_Themes/Images/icon_calendar.jpg" />
<ajaxtoolkit:calendarextender runat="server" ID="calExtender2" Format="dddd, MMMM dd, yyyy" PopupButtonID="btnDate2" TargetControlID="txtDate" OnClientDateSelectionChanged="CheckDateEalier" /> </td>
</tr></table>
</fieldset>
<!-- ============================== Fieldset 1 end ============================== -->
Javascript
<script type="text/javascript">
function CheckDateEalier(sender, args)
{
if (sender._selectedDate < new Date())
{
alert("Day earlier than today cannot be selected.");
sender._selectedDate = new Date();
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}
}
</script>