Since I couldn’t get any solution for my question related to jQuery datapicker, I thought I might need to write a code to verify the date myself. I have a textbox with date in format mm.dd.yyyy. How can I validate date in textbox should not be greater than the current date on blur?
Reminder.config = {
BaseURL: "Reminder.ashx?" + Reminder.BaseURLQuery,
tblHistory: "#tblHistory",
txtNotes: "#txtNotes",
txtDate: "#txtDate",
btnSave: "#btnSave",
dateFormat: 'mm.dd.yy',
};
Reminder.Init = function () {
//Set up calendar
var $txtDate = $(Reminder.config.txtDate);
$txtDate.datepicker({
dateFormat: Reminder.config.dateFormat,
onClose: function (dateText, inst) {
try {
$.datepicker.parseDate(Reminder.config.dateFormat, dateText);
} catch (e) {
$txtDate.val('');
};
},
maxDate: '+0'
});
$txtDate.datepicker('setDate', new Date()).blur(function () {
try {
if ($txtDate.val() == '') {
$txtDate.datepicker('setDate', new Date());
}
}
catch (ex) {
var myEx = myWeb.Exception(ex);
myEx.AddData("Method", "$txtDate.datepicker('setDate', new Date()).blur");
}
});
};
First of all, you’re already constraining your date picker to not select dates in the future.
But you don’t say what seems to be the problem with that… Anyway…
A blur even handler like this one should work as expected: