I have input fields with data attribute.I want when click on button in the field total to be the sum of total of all fields. I found the total sum for every field, but how to sum all of them.
<input type="text" id="total">
<div class="field">
<input type="number" min="1" max="255" data-price="2" class="wert">
</div>
<div class="field">
<input type="number" min="1" max="255" data-price="2" class="wert">
</div>
<button id="calc-butt">Sum</button>
jQuery('#calc-butt').click(function() {
jQuery('.field').each(function(){
var price = jQuery(this).find('.wert').attr("data-price");
var cubic = jQuery(this).find('.wert').val();
var total = price * cubic;
});
});
Aucun commentaire:
Enregistrer un commentaire