javascript - Jquery multiplication of two column value in table with form repeater
问题描述
I have below HTML for table row, each row getting added with form-repeater, so it will append [0], [1] on each row input name attributes,
Now I have on more input with read-only billitem_total, where I need multiplication of billitem_quntity and billitem_rate
<tr data-repeater-item="" name="line_items" style="">
<td>
<a href="javascript:;" data-repeater-delete="" class="btn btn-sm font-weight-bolder btn-light-
danger"><i class="la la-trash-o"></i></a>
</td>
<td>
<input type="text" name="[0][billitem_quantity]" class="form-control"
placeholder="Quantity" value="12">
</td>
<td>
<input type="text" name="[0][billitem_rate]" class="form-control"
placeholder="Rate" value="5">
</td>
<td>
<input readonly="" type="text" name="[0][billitem_total]" id="billitem_total" class="form-
control" style="border: 0;" value="" placeholder="Item name">
</td>
</tr>
How can I do multiplication with help of Jquery for each repeating rows?
Thank you :-)
解决方案
if your data is dynamic means your row will repeat then instead of giving Id's to the inputs give class to the inputs.
<input type="text" name="[0][billitem_quantity]" class="form-control billitem-quantity" placeholder="Quantity" value="12">
<input type="text" name="[0][billitem_rate]" class="form-control billitem-rate" placeholder="Rate" value="5">
<input readonly="" type="text" name="[0][billitem_total]" class="form-control billitem-total" style="border: 0;" value="" placeholder="Item name">
You can chose your event according to your requirement. But keyup will be the better option according to me in your case
$('.billitem-quantity, .billitem-rate').on('keyup', function() {
const quantity = $(this).closest('tr').find('.billitem-quantity')first().val();
const rate = $(this).closest('tr').find('.billitem-rate').first().val();
// Assign the total to the total
$(this).closest('tr').find('.billitem-total').first().val(parseFloat(quantity) * parseFloat(rate));
});
推荐阅读
- python - 使用 TF Layers 替换 GPU 上的 Data Pipeline
- slate - Skywise Slate - 如何在查询中设置多个过滤器功能?
- python - 如何更改子图中一个图的长度?
- ios - SwiftUI:WebP 图像未在 WatchOS 中加载
- spring - MultipartFile VS FileItem VS File,有什么不同?
- typescript - 将导入的类附加到命名空间
- android - 使用 viewpager 创建多个片段
- python - 识别 Pandas DataFrame 中字符串类型内的日期
- javascript - 使节点列表内容的成员可编辑?
- c - "int *x" 是指向 int 类型的指针还是指向整数值的指针?