Search code examples
javascriptjqueryeonasdan-datetimepicker

Load date to input field after selecting from Bootstrap datetimepicker


What I am trying to do is, after selecting a date on Bootstrap Datetimepicker, it should load a value on my input field, but I don't know how to do that. There's my JSFiddle.

This is my jQuery for datetimepicker

$(function () {
    $('.datetimepickerinline').datetimepicker({inline: true});
});

I need to use it for all inputs, or in other words, closest input field.


Solution

  • Here is solution you want: jsfiddle

    $('.datetimepickerinline').on('change dp.change', function(e){
        $('input').val($(this).data('date'));
    });
    

    See reference here

    Further more, I noticed that you want use moment.js

    You can use something like this, using custom format:

    $('.datetimepickerinline').on('change dp.change', function(e){
       $('input').val(moment($(this).data('date')).format('DD/MM/YYYY, h:mm'));
    });