I'm working on a hotel booking website. I have basic form with Check-in, Check-out, No. of adults, No. of Children on the main page. When the user enters these details and clicks on "Book Now", another page(booking page) with more input fields will load. On this page, I want to display the selected values from the previous page. I can display the dropdown values but unable to display the datepicker value from the previous page onto this page's datepicker field. How can I get the datepicker values to display onto the 2nd page datepicker field? Thanks for your help.
I've tried to POST the values in the input field of the datepicker but it didn't work. I can get the 1st page datepicker values to POST as text but not in the datepicker field.
This is the datepicker input field on the main page
<div class="booking_dropdown">
<input type="text" class="datepicker booking_input booking_input_a booking_in" placeholder="Check in" required="required" name="checkin">
</div>
<div class="booking_dropdown">
<input type="text" class="datepicker booking_input booking_input_a booking_out" placeholder="Check out" required="required" name="checkout">
</div>
This is the second page datepicker input field
<div class="booking_dropdown">
<input type="text" id="checkin" class="datepicker booking_input booking_input_a booking_in" placeholder="Check in" required="required" name="checkin" value="<?php echo date_format(date_create($_POST['checkin']),"d/m/Y");?>">
</div>
<div class="booking_dropdown">
<input type="text" id="checkout" class="datepicker booking_input booking_input_a booking_out" placeholder="Check out" required="required" name="checkout" value="<?php echo date_format(date_create($_POST['checkout']),"d/m/Y");?>">
</div>
This is the 2nd page datepicker code - UPDATED
function initDatePicker()
{
if($('.datepicker').length)
{
$("#checkin").datepicker({
minDate: 0,
onSelect: function (date) {
var date2 = $('#checkin').datepicker('getDate');
date2.setDate(date2.getDate());
$('#checkout').datepicker('setDate', date2);
//sets minDate to dt1 date + 1
$('#checkout').datepicker('option', 'minDate', date2);
}
});
$('#checkout').datepicker({
onClose: function () {
var dt1 = $('#checkin').datepicker('getDate');
var dt2 = $('#checkout').datepicker('getDate');
//check to prevent a user from entering a date below date of dt1
if (dt2 <= dt1) {
var minDate = $('#checkout').datepicker('option', 'minDate');
$('#checkout').datepicker('setDate', minDate);
}
}
});
}
}
I expect the selected datepicker value from the 1st page to display on the 2nd page datepicker field but it is not displaying the 1st page datepicker value. I want the date format to be dd/mm/yyyy.