JavaScript に小さな if/else 問題があります。ロジックが見えない…
この関数は、2 つの日付が存在するかどうかを確認し、存在しない場合はアラートを発します。すべてがOKなら、そう言うはずです...
function update_booking() {
//from_date = The date of arrival
//to_date = The date of departure
var alert = ""; //reset alerts
//get variables from booking form input
var from_date = new Date(document.getElementById('from').value);
var to_date = new Date(document.getElementById('to').value);
//if arrival and departure date is present
if(from_date && to_date) {
var alert = "Everything is OK";
}
//if one or two dates are missing
else {
//if arrival and departure dates are missing
if(from_date == 'undefined' || to_date == 'undefined'){
var alert = "Arrival date and departure date are missing";
}
//if from_date is missing update with value from to_date
if(from_date == 'undefined') {
var alert = "Arrival date are missing";
}
//if to_date is missing update with value from from_date
if(from_date == 'undefined') {
var alert = "Departure date are missing";
}
} //end else if one or more date(s) missing
//write alerts
document.getElementById('alert').innerHTML = alert;
}