I have a form with several inputs number, each input has an attribute called product_val
that contains a value.
I need to change the contents of an input (change), a particular function captures all the inputs of the form, get the value of the attribute and multiply by its value, after obtaining this result, add them all into a variable. >
Input class: order_input_qnt
Result of the sum: order_total_price
No jsfiddle
jQuery(function ($)
{
$('.order_input_qnt').on('change',function()
{
$(".order_total_price").html("...");
var sum = 0;
$(".order_input_qnt").each(function()
{
if ($(".order_input_qnt").val().length > 0) {
var valor = parseFloat($(".order_input_qnt").attr("product_val")) * parseFloat($(".order_input_qnt").val());
sum += valor;
}
});
$(".order_total_price").html(sum.toFixed(2));
});
});