Ok so I writ some JQuery for updating a price live when a user adds an extra. There is one chunk of code for Booster Seats and one for Child Seats.
Here is one, so you can see exactly what I do:
$('.boostseat').change(function() {
//sets the var id as the id of the select box
var id = this.id;
//sets this as the value of the select box
numberofboostseat = $(this).val();
//shows a confirmation message
$('#boostseatadd-'+id).show();
//this handles if an item is removed, so that the value doesn't reset
if (typeof(boosttotal) != "undefined" && boosttotal !== null) {
price = $("#hiddenprice").val() - boosttotal;
}else{
price = $("#hiddenprice").val();
}
//number of days you hire it for cariable
numofdays = "<?php echo $length->days; ?>";
if (numofdays > 4){
//alert ("boost if1");
boostcost = Number(20);
}else if ((numberofboostseat == 1 || numberofboostseat == 0) && (numberofchildseat == "undefined" || numberofchildseat == 0)){
//alert ("boost if2");
boostcost = Number(3) * Number(0);
}else if (numofdays < 1){
//alert ("boost if3");
boostcost = Number(3) * Number(1);
}else{
//alert ("boost if4");
boostcost = Number(3) * Number(numofdays);
}
// determines final price
boosttotal = Number(numberofboostseat) * Number(boostcost);
//more varaibles
newprice = Number(price) + Number(boosttotal);
//updates hiddden fields
$("input#hiddenboostprice").val(boosttotal);
$("input#hiddenboostnum").val(numberofboostseat);
$("input#hiddenprice").val(newprice);
oldnumofboost = $("input#hiddenboostnum").val(numberofboostseat);
//updates the HTML (Live Price Update) as decimal
$('#'+id).html("€" + newprice.toFixed(2));
});
});
I've tried to comment it a bit to make it clearer. There is another chunk of code like this that handles child seats.
My problem is the the first childseat OR booster seat is free.
I tried this:
}else if ((numberofboostseat == 1 || numberofboostseat == 0) && (numberofchildseat == "undefined" || numberofchildseat == 0)){
As you can see above, the variable boostcost counts the cost of the seats. The other chunk of code, the childseat one also has global variables i can use, similar to these.
Can anyone suggest an if statement that would effectively make the first child OR booster seat free?
Number(x)?