1

I've been working with this DateTimePicker library. I need to catch the value of the date when I click on it and then pass it to the input's value, or just catch the value because the input works with a submit() onChange.

The library has a full code list but I don't use javascript language, I'm more used to PHP, so I don't know how to do it.

<input type="datetime" name="datetimepicker" id="datetimepicker" onChange="submit()" value="here I need to put the picked date">
jQuery.datetimepicker.setLocale('es');

$('#datetimepicker').datetimepicker({
    inline: true,
    parentID: '#datetimepicker',
    minDate: (0),
    dayOfWeekStart: (1),
    timepicker: false,
    disabledWeekDays: [0,
      <?php echo $reserva['lunes']; ?>,
      <?php echo $reserva['martes']; ?>,
      <?php echo $reserva['miercoles']; ?>,
      <?php echo $reserva['jueves']; ?>,
      <?php echo $reserva['viernes']; ?>,
      <?php echo $reserva['sabado']; ?>],
    disabledDates: ['2019-07-23'],
    formatDate:'Y-m-d',
    format: 'Y-m-d H:i',
    formatTime: 'H:i',
    minTime: '8:00',
    maxTime: '21:00',
    step: (60),
    allowBlank: false,
});
Sami Ahmed Siddiqui
  • 2,328
  • 1
  • 16
  • 29
max
  • 13
  • 5

1 Answers1

0

Guessing from your question, you should be able to use the onChangeDateTime:function to trigger the form submit like this:

jQuery('#datetimepicker').datetimepicker({
  timepicker:false,
  onChangeDateTime:function(dp,$input){
    //alert($input.val())
    $('form#myForm').submit();
  }
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.css" integrity="sha256-kIxwtDqhOVbQysWu0OpR9QfijdXCfqvXgAUJuv7Uxmg=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js"></script>

<form id="myForm" action="/action_page.php">
  Appointment:<br>
  <input id="datetimepicker" type="text" >
  <br><br>
  <input type="submit" value="Submit">
</form> 

As an alternative to the jQuery form submit you could also do send the data via AJAX as shown here.

PS: The result is not properly rendered here but it works.

wp78de
  • 18,207
  • 7
  • 43
  • 71