I have a form where people enter quantities they want from a list of products. Each input value represent the amount they want and the attribute data-price stores the price of the product.
I am using this jquery code to sum put the fields values
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$(".number.qty_input").each(function() {
$(this).keyup(function(){
calculateSum();
});
});
});
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".number.qty_input").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#the_price_v_m").html(sum.toFixed(2));
}
Now I need to customize it so that It allows me to multiply field value by attribute data-price each one of them has. I have already tried a few unsuccessfull methods and I wonder if I could get some help on this.
Thanks!
oh by the way the html I use is
<input type="text" class="number qty_input valid" data-price="15">
<input type="text" class="number qty_input valid" data-price="15">
<input type="text" class="number qty_input valid" data-price="15">
<input type="text" class="number qty_input valid" data-price="15">
<input type="text" class="number qty_input valid" data-price="15">
<input>by thedata-priceattribute, and then sum the total?