1
I need to do a real-time calculation with Divs with the same class inserting the result into another.
The code I’m trying to develop is in the link below
var qtde_inputs = $('.quant').value;
var soma_inputs = 0;
$('.quant').each(function calcula(i,item){
var valorItem = parseFloat($(item).val());
if(!isNaN(valorItem))
soma_inputs += parseFloat($(item).val());
document.getElementById('seu_campo_destino_da_soma').value = (soma_inputs).toFixed(2);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="text" class="quant" value="10" onblur="calcula()">
<input type="text" class="quant" value="10" onblur="calcula()">
<input type="text" class="quant" value="40" onblur="calcula()">
<input type="text" id="seu_campo_destino_da_soma">
<form>
I guess? What kind of calculation?
– Rafael Augusto
I need to calculate these three inputs: <input type="text" class="Quant" value="10" onblur="calculates()"> <input type="text" class="Quant" value="10" onblur="calculates()"> <input type="text" class="Quant" value="40" onblur="calculates()"> Giving output on this <input type="text" id="seu_campo_destino_da_soma">
– user99476
In case using JS to sum inputs with real-time Quant class giving the result in the total input, if it is necessary to create an i++ to generate a different Quant, but it is automated to search understand?
– user99476