in jquery ui datepicker, on the OnSelect() event is there anyway to get the previous selected date
i have code on the onSelect event of the jquery ui datepicker and i now want to only run my function if the date has changed values (so if a user selects a date that was already there in the textbox, i don't want to run this code as it will be a redundant calculation). Here is my existing code.
$('#Milestone').datepicker(开发者_运维问答{
dateFormat: 'dd M yy',
onSelect: calcUpdate
});
According to http://api.jqueryui.com/datepicker/#option-onSelect, you should try this:
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: function(curDate, instance){
if( curDate != instance.lastVal ){
//so, the date is changed;
//Do your works here...
}
}
});
The onSelect function receives 2 parameters which are used here; You can debug/console the values of the 2nd parameter to know more about it.
You can use data to store previously stored value and compare the current value to it.
Try this(put these statements in your document ready event):
$('#Milestone').data("prev", $(this).val());
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: function(dateText){
var prevDate = $(this).data("prev")
var curDate = dateText;
if(prevDate == curDate){
$(this).data("prev", curDate)
calcUpdate();
}
}
});
精彩评论