Hi,
I am working on a project which has a combobox to select the hotel rooms. After select the hotel room, in the next text field, user has to select his arrival date and departure date. This arrival date is jquery datepicker plugin and I need disable rooms unavailable dates.
This is my jquery code
- $("#select_villa").live('change', function(){
var dataString = 'villa=' + $("#select_villa").val();
$.ajax({
type: "GET",
url: "include/getdate.php",
data: dataString,
dataType: "json",
success: function(data){
var d= data[0].unavailable_date_from;
var d2 = data[0].unavailable_date_to;
var t = d.getTime();
var t2 = d2.getTime();
var d3 = t2 - t;
var d4 = new Date(d3);
var d5 = d4.getDate();
var today = new Date();
var todTime = today.getDate();
var fromdate = d.toString().substring(7, 10);
var todayTime = today.getTime();
var dateDiff;
var date1;
var no_of_days;
//alert(d5);
if(t > todayTime){
dateDiff = t - todayTime;
date1 = new Date(dateDiff);
no_of_days = date1.getDate();
//alert(no_of_days-1);
}else{
dateDiff = todayTime - t;
date1 = new Date(dateDiff);
no_of_days = date1.getDate();
//alert(no_of_days-1);
}
$("#textfield1").datepicker({
dateFormat: 'yy-mm-dd',
minDate: +no_of_days+"D",
maxDate: +d5-1+"D"
});
}
});
return false;
});
This is my php code
- <?php
include("db.php");
$returnArray = array();
$villa = $_GET['villa'];
$sql = mysql_query("SELECT unavailable_date_from, unavailable_date_to FROM villa WHERE name = '".$villa."'");
while($row = mysql_fetch_array($sql)){
$returnArray[] = $row;
}
echo json_encode($returnArray);
?>
In my current code, I could select the no.of days between to and from dates and the number of days between to and day and today date. I need to disable the dates between to and from dates in order to let the user know those days has already booked. Please somebody help me to solve this problem.
If you know a better way to solve this other than this code snippet, pls provide me, that would be a great help
Thank You
Regards,
Mujahid