1
I need to get the +index work as it is a page generation system with embedded products. In case, every product inserted will have a total0 + total1
and so on. But it has to be in real time the value!
function Soma(){
var soma = 0;
$('#total'+index).each(function(){
var valorItem = parseFloat($(this).val());
if(!isNaN(valorItem))
soma += parseFloat(valorItem);
});
$('#final').val((soma).toFixed(2));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="">
Total produto1: <input type="text" id="total0" onblur="Soma()" value="0"><br>
Total produto2: <input type="text" id="total1" onblur="Soma()" value="0"><br>
<br>
Total todos os produtos: <input type="text" id="final">
</form>
It worked perfectly, obliged I only had to change to the class because the name I will use for the POST method.
– user99476
I don’t recommend using the class, because it would be reserved to indicate a style class in css, you can use any other custom and arbitrary attribute. I’ll edit the answer
– Leandro Angelo
I stay in the waiting then, at first it already worked, although I will not use the class even as I already use the bootstrap
– user99476