JSFiddle - React, Tailwind, and code Playground
by Fernando Leal
HTML
<input id="edtPesos1" class="soma"/>
<input id="edtPesos2" class="soma"/>
<input id="edtPesos3" class="soma"/>
<button id="btnSoma">Somar</button>
JavaScript
function somaPesos(){
var soma = 0;
var itens = document.getElementsByClassName("soma");
for(i = 0; i < itens.length; i++){
var item = parseInt(itens[i].value);
alert(item);
soma = soma + item;
}
alert(soma);
return false;
}
var btnSoma = document.getElementById("btnSoma");
btnSoma.addEventListener("click", somaPesos);