Search code examples
jquerybootstrap-datetimepickereonasdan-datetimepicker

Detect Changes Made to Input Field by Bootstrap Datetimepicker


I set my input field so that when user clicks on it, a Bootstrap Datetimepicker is shown. I want to calculate something based on the date that is being entered in that input field through the datetimepicker.

I have thus defined my calculating function as:

$("#dob").on("input change bind", function (e) {
        //calculate age here.
    });

"dob" is the id for the input box. Datetimepicker correctly enters the datetime to the field. Code:

$('#dob').datetimepicker({
            format: 'YYYY-MM-DD',
            showClose: true
        });

Curiously, this bit of code works if I manually enter the date

$("#dob").change( function () {
        alert('DOB');
    });

But it is not called when the date is selected through Bootstrap Datetimepicker. What's causing the problem here?


Solution

  • try

    $('#dob').change(function () { //OR $('#dob').on('change',function ()
        console.log($('#date-daily').val());
    });
    

    UPDATE

    $('#dp3').datepicker().on('changeDate', function (ev) {
        $('#dob').change();
    });
    $('#dob').change(function () {
        console.log($('#dob').val());
    });