Dear friends, I'm trying to add sum between html and javascript inputs, but with this example, I've just been able to put in the html input. How do I implement in the javascript input and add the value along with the Total Value?
NoHtmllookslikethis:
html
<scripttype="text/javascript">
function calcular(){
var valor1 = parseInt(document.getElementById('txt1').value);
var valor2 = parseInt(document.getElementById('txt2').value);
document.getElementById('result').value = valor1 + valor2;
}
<div class="form-group col-md-3">
<label for="titulo">Valor:</label>
<input type="text" class="form-control" value="0" id="txt1" name="responsavel" onfocus="calcular()" >
</div>
<div class="form-group col-md-3">
<label for="titulo">Valor Total:</label>
<input type="text" class="form-control" name="responsavel" id="result" readonly>
</div>
In the javascript where I add other dependents like this:
javascript
AddTableRow = function() {
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" name="usuarios['+ currentRow + '][nome]"></td>';
cols += '<td><input type="text" name="usuarios['+ currentRow + '][cpf]"></td>';
cols += '<td><select name="usuarios['+currentRow +'][cargo]">';
cols += '<option value="gerente" name="usuarios['+currentRow +'][gerente]">Gerente</option>';
cols += '<option value="Professor" name="usuarios['+currentRow +'][Professor]">Professor</option>';
cols += '<option value="Programador" name="usuarios['+currentRow +'][Programador]">Programador</option>';
cols += '</select></td>';
cols += '<td><input type="text" name="usuarios['+currentRow +'][email]"></td>';
cols += '<td><input type="text" name="usuarios['+currentRow +'][parentesco]"></td>';
cols += '<td><input type="text" id="txt2 onblur="calcular()" name="usuarios['+currentRow +'][valor]"></td>';
cols += '<td class="actions">';
cols += '<button class="btn btn-large btn-danger" onclick="RemoveTableRow(this)" type="button">Remover</button>';
cols += '</td>';
newRow.append(cols);
$("#products-table").append(newRow);
currentRow++;
return false;
};