1
I was reading some tutorials and saw a Javascript function to add two inputs and show in real time. It works perfectly.
However, I would like to use it to multiply the values, however I could not modify the function, so when I make changes to the code I get an error.
function Soma(){
var soma = 0;
var ipts = document.querySelectorAll('input[oninput="Soma()"]');
for(var x=0; x<ipts.length; x++){
var valorItem = parseFloat(ipts[x].value);
!isNaN(valorItem) ? soma += parseFloat(valorItem) : null;
}
document.querySelector('#final').value = soma.toFixed(2);
}
<form action="">
Total produto1: <input type="text" oninput="Soma()" value="0"><br>
Total produto2: <input type="text" oninput="Soma()" value="0"><br>
<br>
Total todos os produtos: <input type="text" id="final">
</form>
Luiz Felipe, I changed the signs, but it wasn’t working here in my code. I appreciate the answers. Thank you very much personally!!
– Thiago Silva