I am using the ajax calendarextender and javascript to restrict that the user will not select the past date but here i’m facing an issue:
- If the user is selecting the past date then it is working fine
- If the user is selecting future date then also it is working fine
But if the user is selecting the current date then also he is getting alert which is not required.
My requirement is that the user can select current date plus the future date but restrict to enter any previous date. Please help me to solve this issue, below you can find the code:-
<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>
this is because the date is same but time is different set hour min sec and milli seconds to 0 then it will work.