I have a table that generates rows when I click a button. In these lines there are two inputs (amount and price) that I need to get the values entered, multiply and the result display in a total column when the user clicks out of the input while the two are 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>