I have a function which checks if a search in the pickup address contains an airport as follows:-
function checkIsAirport(str) {
var myRegExp = /\bAIRPORT\b/i;
return str.match(myRegExp);
}
// Check if label contains an airport..
if (checkIsAirport(label.html()) != null &&
label.parent().parent().attr('title') == "Pickup") {
//FUNCTION
}
Basically what I am needing to do is add a 'surcharge' of 'x' amount if the pickup contains an airport address. So if a airport is set to Gatwick, this is then sent to tariff.fare.controller.php which will add 'x' to the fare. I was just wondering how would be the best way about doing this.
Also, if a user changes the pickup from an airport to a none airport address, 'x' would have to be subtracted from the fare.
Any help would be much appreciated!
:: EDIT ::
Just to add, to achieve this I am wanting to use AJAX. As soon as a user enters an airport in the pickup address a request needs to be sent to my TariffFareController class to the following function:
private static function getFinalFare($fare) {
$final_fare = ($fare * self::$fare_factor);
if (self::$str_wait_return == "true") {
$final_fare = $final_fare * 2;
}
if (self::$str_return == "true" && self::$return_date != "false" && self::$return_time != "false") {
// We need to calc to fare based on the return date and time
$return_fare = self::getFare(1);
// Append to final fare
$final_fare = $final_fare + $return_fare;
}
// Create new journey object with the info that we have so far
/*$journey = new Journey($journey_id,$pickup,$dropoff,$vias,$distance,$vehicle,
$date_time,$return_journey,$meet_greet,$extras);*/
return number_format($final_fare,2);
}
so that I can read the 'surcharge' value from the database and then add this to the fare calculation.