5
Dear friends, I am trying to add sum between html and javascript inputs, but with this example, I was only able to put in the html input. How do I implement the javascript input and add the value together with the Total Value?
In Html this is how:
html
<script type="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 this way:
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;
};
Can you adapt jsFiddle to your code with the remaining problem? https://jsfiddle.net/L4sy0gk8/
– Sergio
Check out @Sergio https://jsfiddle.net/9zv3k4m3/2/# - When I add more dependents, the value does not add up
– Mauro Santos