JavaScript Date Validation using Ajax Calender to check the date is greater than or equal to the current date

Rajeshk_cgm
Rajeshk_cgm used Ask the Experts™
on
hi.. i need to to the  Date Validation to check the date is greater than or equal to the current date in Ajax Calendar (using javascript)

i have used onclientdateselectionchanged event..

Its working fine., but problem after shows the Alert message it should focus the text box and the ajax calender popup show be true..

its getting flicker.,


function CheckDateEalier(sender,args)
    {
        if (sender._selectedDate < new Date())
          {
             alert("You cannot select a day before today!");
             sender._selectedDate = new Date();
             sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }       
    }
 
 
<asp:TextBox ID="txtdate" runat="server" CssClass="forTextbox"  onkeypress="CheckForNumeric(event);"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalExtendrdeliverydate" runat="server" TargetControlID="txtdate" CssClass="cal_Theme1" OnClientDateSelectionChanged="CheckDateEalier" >
                                                            </ajaxToolkit:CalendarExtender>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
Try to return false from your CheckDateEalier function. You can set the focus back by setting the focus:

function CheckDateEalier(sender,args)
{
    if (sender._selectedDate < new Date())
    {
        alert("You cannot select a day before today!");
        sender._selectedDate = new Date();
        sender._textbox.set_Value(sender._selectedDate.format(sender._format))
        sender.focus();
        return false;
    }       
}

Open in new window

Top Expert 2009

Commented:
The user had forgotten to cancel the event by returning false, this is a common bug with javascript. I pointed out that error and gave a tested solution for the problems, incl. the focus issue.

Request to accept http:#24931373 (abel) as solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial