javascript - JS script to calculates sum of amount calculates wrong -


i have prepared this jsfiddle ilustrates how script calculate twice sum of each selected option attribute price. please me solve issue.

optionsamount wrong, mean calculated twice.. why that? 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); } 

try this,

function update_amounts(){ var sum = 0.0;  $('#basketorder > tbody  > .product').each(function() {      var optionsamount = 0.0;       $(this).find('.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); 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -