0
I have a table that generates lines by clicking a button. In these lines there are two inputs (amount and price) that need to take the entered values, multiply and the result display in a column of total when the user click out of the input being both filled. I’m not sure how to do this multiplication and display the result.
<table class="table m-0" id="products-table">
<thead>
<tr>
<th>Produto/Serviço</th>
<th>Quantidade</th>
<th>Valor Unitário</th>
<th>Valor Total</th>
<th>Remover</th>
</tr>
</thead>
<tbody class="row">
</tbody>
<tfoot>
<tr>
<td colspan="5" style="text-align: left;">
<button class="btn btn-info waves-effect w-md waves-light m-b-5" onclick="AddTableRow()" type="button">Adicionar Produto</button>
</td>
</tr>
</tfoot>
Script
<script>
function amount(value) {
var amount = value;
return amount;
}
function price(value) {
var price = value;
return price;
}
function total(amount, price) {
total = amount * price;
}
$(document).ready(function() {
RemoveTableRow = function(handler) {
var tr = $(handler).closest('tr');
tr.fadeOut(400, function(){
tr.remove();
});
return false;
};
AddTableRow = function() {
var newRow = $("<tr>");
var cols = "";
cols += '<td class="col-md-4"><input type="text" class="form-control product" name="product[]"></td>';
cols += '<td class="col-md-2"><input type="text" class="form-control amount" name="amount[]" onkeyup="amount(this.value)"></td>';
cols += '<td class="col-md-2"><input type="text" class="form-control price" name="price[]" onkeyup="price(this.value)"></td>';
cols += '<td class="col-md-2 total">R$ 100,00</td>';
cols += '<td class="col-md-2">';
cols += '<a onclick="RemoveTableRow(this)" type="button"><i class="zmdi zmdi-delete zmdi-hc-lg"></i></a>';
cols += '</td>';
newRow.append(cols);
$("#products-table").append(newRow);
return false;
};
});
</script>
Can you explain the account you want to do and how it starts? by clicking on which button?
– Sergio
It is just a multiplication between the amount (quantity) and price (price) field and the result in the total column. There would be no button, the result would appear when clicking outside the iinputs, with both filled.
– Marcelo