0

I am developing a simple check-in and check-out form with Datepicker and I made it to always display the checkin as today, and checkout as tomorrow.

<?php
$today = date("Y-m-d");
$tomorrow = new DateTime('tomorrow');
?>
<div class="row">
     <input type="text" class="datepicker" name="datein" value="<?php echo $today; ?>" readonly='true'>
     <input type="text" class="datepicker" name="dateout" value="<?php echo $tomorrow->format('Y-m-d'); ?>" readonly='true'>
</div>

And I want the checkout date to be always the checkin + 1 day. Is there a way to dynamically check the checkin value and update the checkout on any event, or should I take a different approach?

Thank you

Kristián Filo
  • 827
  • 2
  • 8
  • 25

1 Answers1

0

Try this

<input id="checkIn" type="text" class="datepicker" name="datein" value="" readonly='true'>
     <input id="checkOut" type="text" class="datepicker" name="dateout" value="" readonly='true'>


 $(function () {         
var dateToday = new Date(new Date().getTime();
var oneDayAhead = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);

   $("#checkIn").datepicker({
       changeMonth: true,
       minDate: dateToday,
       dateFormat: 'yy-mm-dd',
   });

   $("#checkOut").datepicker({
           changeMonth: true,
           minDate: oneDayAhead,
           dateFormat: 'yy-mm-dd',
        });
});

What this basically does is, it will restrict checkout time one day ahead of current time, You can modify this to suit your needs

user7747472
  • 1,874
  • 6
  • 36
  • 80
  • Thank you, but it doesn't seem to work. The checkOut won't change. – Kristián Filo Apr 13 '18 at 06:21
  • you want it automatically prefield the check out date? – user7747472 Apr 13 '18 at 06:34
  • No, I can get it to prefield. But I want it to change along with the first field. E.g. I choose April 1st in the first field, and I want it to set April 2nd to the second field (+1 day). Your solution makes sense, but it does not work, as you can see in the fiddle. – Kristián Filo Apr 16 '18 at 10:44