I have dynamic table where button on click add a new table row. On each row there is price, qty and total price input field. I want that when user put value on qty field, it will multiply price and qty and show on total price input.
My Code:
$(document).ready(function(){
var product = '
<tr>
<td>
<select name="product_id" class="form-control" id="product-name">
<option value="" selected disabled>Select Product</option>
@foreach($product as $row)
<option value="{{$row->id}}">{{$row->product_name}}</option>
@endforeach
</select>
</td>
<td><input type="number" name="p_price[]" class="form-control p_price"></td>
<td><input type="number" name="p_qty[]" class="form-control qty" ></td>
<td><input type="number" name="p_total" class="form-control t_price" ></td>
<td><button class="btn btn-danger delete theme-danger btn-xs"><i class="fa fa-times" aria-hidden="true"></i></button></td>
</tr>
';
$("#productAdd").click(function(){
$('#product-table tbody').append(product);
});
$(document).on('click','.delete',function(){
$(this).parents('tr').remove();
});
$(function() {
$(document)
.on('input', '.qty');
$('.t_price').val($('.p_price').val() * $('.qty').val());
});
});
How can I calculate each row value?