189
rated 0 times
[
194]
[
5]
/ answers: 1 / hits: 27836
/ 10 Years ago, thu, may 8, 2014, 12:00:00
I am trying to compare start date and end date in jquery. Code in aspx page looks like:
<asp:TextBox ID=tbStartDate runat=server CssClass=textbox Width=80px contentEditable=false onchange=javascript:compareDates();></asp:TextBox>
<asp:ImageButton runat=Server ID=ibStartCalendar ImageUrl=~/Images/calendar.jpg
Height=18px AlternateText=Click to show calendar />
<act:CalendarExtender ID=ceStartDate runat=server Format=dd-MMM-yyyy TargetControlID=tbStartDate PopupButtonID=ibStartCalendar CssClass=Calendar>
</act:CalendarExtender>
And javascript function:
function compareDates() {
var start = $(#<%=tbStartDate.ClientID %>).val();
var end = $(#<%=tbEndDate.ClientID %>).val();
if (!compareDate(start, end)) {
$(#<%=lblMsg.ClientID %>).html(Start Date can not be greater than End Date);
}
}
function compareDate(start, end) {
if (start.length > 0 && end.length > 0) {
var stDate = new Date(start);
var enDate = new Date(end);
var compDate = enDate - stDate;
if (compDate >= 0)
return true;
else {
return false;
}
} else { return true; }
}
Requirement is to dispaly date in dd-MMM-yyyy format in text boxes to I can not change format in calenderExtender.
When I keep this format star date and end date becomes NaN. If I change format in calenderExtender i get proper results. However as I said I can not change format there. How can I change format in javascript?
More From » jquery