I need to make + index work because it is a system for generating pages with embedded products. In this case, each inserted product will have a total0 + total1
and so on. However, 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><formaction="">
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>