Search code examples
bootstrap-4tempus-dominus-datetimepicker

Is there a way to retrieve the updated datetime when text input changes?


I have a datetimepicker and a button. The user selects a date time, then hit the button. The selected date time is shown in an alert.

https://jsfiddle.net/jeffxiao/rfzm8pyt/

$(function() {
  $('#datetimepicker1').datetimepicker();

  $('#buttonGo').click(function() {
      var moment = $("#datetimepicker1").datetimepicker("date");
      alert(moment.format('MMMM Do YYYY, h:mm:ss a'));
  })
});

The question is, if the user changes the text for the input, instead of choosing from datetimepicker, is there a way to retrieve the updated datetime (in the text)?

My test shows the default is to retrieve the selected in the picker, NOT the updated text in the text box.


Solution

  • Does that help ? Set an id to your input to retrieve data.

    https://jsfiddle.net/djibe89/kx1rnbm9/

    $(function() {
      $('#datetimepicker1').datetimepicker();
    
      $('#buttonGo').click(function() {
          var time = $("#input-datetimepicker").val();
          alert(time);
      })
    });