0
I rephrased that question, I’ll try to be more objective. I have that field on the form:
Where the area code you calculate is this:
$( "div#molhos :checkbox:checked" ).each(function() {
sub += $( this ).val() * $( this ).parent().find("select").val();
}); // each molhos
So far so good, what I need is that at the end of the calculation it subtracts ONE, example: If the user chooses THREE SAUCE 1 and TWO SAUCE 3 the total will be 5 sauces, correct? It would be R $ 7,50, but I want the result always stay with LESS ONE, would be the right amount R $ 6,00.
The Rule would be, choosing ONE sauce only, comes out for free, from the second we will charge.
I don’t know if it helps, but there’s more code information: It gets me to the top:
var str = "";
var id = "";
var sub = 0.00;
var taxa = 0;
var taxadeentrega = total - taxa;
var total = 0.00;
var qcount = 0;
var scount = 0;
var opc = 0;
var options = "";
for (i=1; i<21; i++){
options += "<option value='" + i + "'>" + i + "</option>";
}
This is another area of code that is mentioned the Sauce:
<!--MOLHOS-->
$( "div#molhos :checkbox:checked" ).each(function() {
var sel = $(this).parent().children("select").val();
str = str + $(this).parent().children("strong").text() + ": R$ " + $(this).val().replace(".", ",") + " x " + sel + " = R$ " + (($(this).val() * sel).toFixed(2)).replace(".", ",") + "<br>";
})
$('input[name=molhos]').val(str);
str = "";
But I believe that the important part to create this rule is the first of this post! I believe it is the Rule if, but I can not do, tried everything!!
look at the code of another field I have in the form, which works with select. This does not have the option for free!
$( "div#sobremesas :checkbox:checked" ).each(function() {
 var sel = $(this).parent().children("select").val();
 str = str + $(this).parent().children("strong").text() + ": R$ " + $(this).val().replace(".", ",") + " x " + sel + " = R$ " + (($(this).val() * sel).toFixed(2)).replace(".", ",") + "<br>";
 })
 $('input[name=sobremesas]').val(str);
 str = "";
– Alessandro Ramos
The part that makes the calculation:
$( "div#sobremesas :checkbox:checked" ).each(function() {
 sub += $( this ).val() * $( this ).parent().children( "select" ).val();
 }) //each sobremesas
– Alessandro Ramos
I could adapt this from Dessert to Sauce, just do not know where I put the option 1 is free. Ie EQUAL to a choice will be 0 of charge
– Alessandro Ramos
What I realized of your problem is this, Oce just needs to know how many sauces were selected, after that, Oce subtracts how many free sauces Oce this giving for free, the rest is what the customer will have to pay. What I did inside the
each()
was exactly calculate the total of sauces that the user selected.– Neuber Oliveira