(function ($) {
"use strict";
$(document).ready(function () {
$('.bookinginput').on('change', function(){
var adults = $('#t_adults_qty').val(),
child = $('#t_children_qty').val(),
pickup = $('#pick_up_list').val(),
priceBase = priceBooking.adult * adults,
priceChild = priceBooking.child * child;
var price = priceBase + priceChild
$('#price_total').val(price);
})
});
}(jQuery));
I will explain my code a bit, basically it is a small mathematical calculation based on the value of the inputs.
I have a json with the variable priceBooking, which has two values (Adult and Child), and I have several inputs with the numbers of the (adults and children).
I simply calculate the number of (Adults for the Adult price) the same with the children.
and the result I put it in the value of another hidden input (#price_total)
I would like to simplify this code or improve it. I want to be able to work with variables globally and not have to duplicate code.
Any suggestions?