How to get the changed date from bootstrap-datepicker

Viewed 18524

I am using Eternicode's fork of the bootstrap-datepicker library and until now all is going well for generating it, but I want to get the date in order to use it in my logic after changing the date.

$('#calendar').on('changeDate', function(event, date) {
  // how to pop alert message to print the date I've chosen ?
});

How can I do this?

4 Answers

Put this code in the jquery function body:

$(document).ready(function () {
  $('#datepicker').on('dp.change', function(){
    var t=Date.parse($("#dob1").val());    
    if (t > Date.now()) {
      alert('Selected date shold not be a future date');
      $("#dob1").val('');
    }
  });
});

There are two things you could try.

Try implementing this line:

$('#startdate').val()

Or this one:

$('#startdate').data('date')

Drew T. suggests using .val() - also very efficient.

$('#calendar').on('changeDate', function(event, date) {
    var date = $('#calendar').val();
    alert(date);
});

Hope this helps!

Related