Reputation: 4717
I am using this code to get the date from the bootstrap-datepicker. I found several question swith the same issue and none of them seem to work for me. I am not sure what I am missing.
<div id="dateCal"></div>
This is my jQuery
$input = $("#dateCal");
$input.datepicker({
format: 'dd-mm-yyyy'
})
.on('changeDate', function(e){
console.log(e.date);
});
and mu console output looks like this:
Sat Jun 21 2014 00:00:00 GMT-0400 (EDT)
What am I doing wrong? I need e.date to come out as the format option is set.
Upvotes: 0
Views: 578
Reputation: 1631
When processing events in javascript (and jQuery or bootstrap), the "e" passed to the function is the event object. Reading e.date
could refer to the datetime of the event. You want to be reading this.value
, where this refers to the HTML element associated with the event, or in this case, your date field.
Do instead:
console.log(this.value);
Upvotes: 1