Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datepicker onSelect Not Firing

I have a date picker but onClose and onSelect will not fire. The code is in document.ready so i know its initialized.

$('#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());
    }
});
like image 524
user2807494 Avatar asked Feb 13 '14 12:02

user2807494


2 Answers

Must this code work when select a date:

$("#datepicker").datepicker({
dateFormat: 'dd/mm/yy'}).on("changeDate", function (e) {
alert("Working");});
like image 107
hamzeh.hanandeh Avatar answered Oct 08 '22 21:10

hamzeh.hanandeh


Some of the Options you are using are not available in datepicker see http://api.jqueryui.com/datepicker/

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

$(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 worked then check for javascript errors in your error console.

like image 27
SFIntegrator Avatar answered Oct 08 '22 21:10

SFIntegrator