Reputation: 3
I have a table like this:
<tbody id="invoice_item">
<tr>
<td><input name='qty[]' type='text' class='form-control form-control-sm qty' value='0'></td>
<td><input name='price[]' type='text' class='form-control form-control-sm price' value='0'></td>
<td><input name='sub_total[]' type='text' class='form-control form-control-sm sub_total' value='0' readonly></td>
</tr>
</tbody>
I want to make Javascript when qty/price change subtotal changed too. My js:
$("#invoice_item").delegate(".qty","keyup",function(){
var qty = $(this).val();
var price = tr.find(".price").val();
alert(price);
var sub_total = qty * price;
alert(sub_total);
tr.find(".sub_total").html(sub_total);
})
$("#invoice_item").delegate(".price","keyup",function(){
var price = $(this).val();
var qty = tr.find(".qty").val();
alert(qty);
})
It seems the trouble is tr.find(".").val();
.
I try to alert it, but no use.. anyone can help? How I can call the other input?
$(this).val();
is no problem.
Upvotes: 0
Views: 341
Reputation: 3
i solved it, i must define it by var tr = $(this).parent().parent();
thanks all!
Upvotes: 0
Reputation: 1941
delegate()
is deprecated in v 3.0. Which jquery are you using?
You can attach the events to the input tags themselves using the new on
method, like so:
$(".qty").on("keyup",function(){}
To get the other input value you can use this:
$(".price").val()
Upvotes: 1