Reputation: 11446
I am wanting to set this jquery date picker to throw an alert / dialog if the date selected is todays date. I am using smarty, thats the date function you see. However when I input todays date, the script will still not return the dialog that represents today. Here is the script:
$("#sanctionDateStart").datepicker({
altField: "#sanctionDateStart_hidden",
altFormat: "yy-mm-dd",
minDate: new Date()
}).datepicker("setDate", "{$data.sanctionDateStart}").change(function () {
$('#sanctionDateEnd').datepicker('option', 'minDate',
$(this).datepicker('getDate'));
if ($(this).datepicker('getDate') == '{date("m/d/Y", $smarty.now)}'){
alert ('Todays Date');
}
else {
alert ('Not Todays Date');
}
});
Upvotes: 1
Views: 388
Reputation: 198388
The date picker returns a Date
object, which can't be equal to a string. You need to convert the string from Smarty into a JS Date
. See the Date
documentation to see how to do that.
Upvotes: 1
Reputation: 7449
Use Datepicker onSelect instead of .change
$('selector').datepicker( {
onSelect: function(date) {
//Do your thing here
//date hold selected date
}
});
Upvotes: 2