Datepicker onSelect Not Firing

I have a date picker but onCloseit onSelectdoesn't work either. The code is in document.ready, so I know its initialization.

$('#DateRangeTo').datepicker({
    beforeShow: function (input, inst) {
        inst.dpDiv.css({ marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth + 'px' });
    },
    format: "dd/mm/yyyy",
    startView: 1,
    //daysOfWeekDisabled: "3,4",
    autoclose: true,
    todayHighlight: true,
    //onClose: function (dateText, inst) { alert("here"); }
    onSelect: function (dateText, inst)
    {
        alert("Working");
    },
    onClose: function (date) {
        var dt = new Date(date);
        alert(dt.getMonth());
    }
});
+3
source share
3 answers

Should this code work when choosing a date:

$("#datepicker").datepicker({
dateFormat: 'dd/mm/yy'}).on("changeDate", function (e) {
alert("Working");});
+6
source

Some of the options you use are not available in datepicker, see http://api.jqueryui.com/datepicker/

And also you are missing $(function () {});. See the updated code below.

$(function () {
            $('#DateRangeTo').datepicker({
                beforeShow: function (input, inst) {
                    inst.dpDiv.css({ marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth + 'px' });
                },
                dateFormat: "dd/mm/yyyy",
                //startView: 1,
                //daysOfWeekDisabled: "3,4",
                //autoclose: true,
                //todayHighlight: true,
                //onClose: function (dateText, inst) { alert("here"); }
                onSelect: function (dateText, inst) {
                    alert("Working");
                },
                onClose: function (date) {
                    var dt = new Date(date);
                    alert(dt.getMonth());
                }
            });
        });

If still not working, check for javascript errors in the error console.

+2
source

The date sensor does not start onSelect if there are multiple inputs with the same identifier. You should not have several elements with the same identifier, but the date picker will show and appear to work and display. Even some of the other methods, like onClose, work, but final onSelect will not

0
source

All Articles