jQuery datepicker, onSelect won't work
I can't get onSelect
working on my jQuery datepicker
.
Heres my code:
<script type="text/javascript">
$(function() {
$('.date-pick').datePicker( {
onSelect: function(date) {
alert(date)
},
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1,
});
});
</script>
It's like it doesn't register the onSelect
function. What am I doing wrong?
No comma after the last property.
Semicolon after alert(date);
Case on datepicker (not datePicker)
Check your other uppercase / lowercase for the properties.
$(function() {
$('.date-pick').datepicker( {
onSelect: function(date) {
alert(date);
},
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1
});
});
datePicker's onSelect equivalent is the dateSelected event.
$(function() {
$('.date-pick').datePicker( {
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1,
}).bind('dateSelected', function(e, selectedDate, $td) {
alert(selectedDate);
});
});
This page has a good example showing the dateSelected event and other events being bound.
$('.date-picker').datepicker({
autoclose : true,
todayHighlight : true,
clearBtn: true,
format: 'yyyy-mm-dd',
onSelect: function(value, date) {
alert(123);
},
todayBtn: "linked",
startView: 0, maxViewMode: 0,minViewMode:0
}).on('changeDate',function(ev){
//this is right events ,trust me
}
});
The best solution is to set the datepicker defaults
folows the code that I used
$.datepicker.setDefaults({
onSelect: function () {
$(this).focus();
$(this).nextAll('input, button, textarea, a').filter(':first').focus();
}
});