Reputation: 291
I have been racking my brain trying to figure this one out. I have looked all over stackOverflow and Google, and nothing seems to be working for me. I have an inline JQuery UI datepicker and want an alert box to pop up when the user selects a date. My code is:
HMTL:
<div id="datePicker1"></div>
JavaScript:
<script type="text/javascript">
$("#datePicker1").datepicker();
$("#datePicker1").datepicker({
onSelect: function(dateText, inst){
alert('hi');
}
});
</script>
The calendar shows up, but when I select any date, nothing happens. I would love to know why. Any help is appreciated. Thanks.
Upvotes: 0
Views: 125
Reputation: 780869
Options are initialized the first time you call datePicker()
on an element. If you want to change the options later, you have to use the option
method:
$(function() {
$("#datePicker1").datepicker();
$("#datePicker1").datepicker("option", {
onSelect: function(dateText, inst) {
alert('hi');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<input id="datePicker1">
Upvotes: 1