I prepared this jsfiddle which illustrates how my script calculates twice as much as the sum of each selected option attribute price. Please help me solve this problem.
optionsamount is incorrect, I mean, computed twice. Why? Thanks
function update_amounts(){ var sum = 0.0; var optionsamount = 0.0; $('#basketorder > tbody > .product').each(function() { $('.selectedoptionselect option:selected').each(function(){ optprice = $(this).attr('price'); optionsamount+= parseFloat(optprice); }) var qty = $(this).find('.qty option:selected').val(); var price = $(this).find('.price').val(); var amount = (qty*price); sum+= (amount + optionsamount); $(this).find('.amount').text(''+ amount.toFixed(2)); }); $('.total').text(sum); }
source share