You must first prepare your HTML to perform the calculation.
- Add a class for those who will participate in the summation
- Add a value to inputs containing the value it represents in the final account
- Add a class to the one that will receive the total.
After this is prepared, you can use Jquery, as I saw you are already using, to go through all inputs of the defined class and, if it is selected, add in the final account.
$(document).ready(function() {
calcTotal();
$('.price-variant').change(function() {
calcTotal();
});
});
function calcTotal() {
var total = 0;
$('.price-variant').each(function() {
var isChecked = $(this).is(':checked');
if(!!isChecked) {
total += Number($(this).val());
}
});
$('.total').text('R$ ' + total.toFixed(2));
}
I made a Plunk with the code working for you to see (I took advantage and put the code of the component below, where you add and remove some.. " additional")
https://next.plnkr.co/plunk/7Mv6RiK8W2x3g5fI
I hope you solve!
Edu, what have you tried? Enter the code of what you’ve already seen
– Ricardo Pontual
Ricardo, I’m not able to enter the code here, but if you open the link click to buy any Burger, you will see that it pulls the modal as I did, does not pull the snack in specific value, and when it marks some check, does not change the value. I could not do javascript, so I decided to come here to try a direction to do from scratch again, because the deadline is today and I no longer know where to turn
– Edu Stadler
Edu, it’s complicated like this. You don’t need to post ALL the page code in the question. Just the problem code, so we can understand what is being done.
– Sam