Search code examples
javascriptjqueryhtml-tablekeyup

Javascript keyup call other table value


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.


Solution

  • i solved it, i must define it by var tr = $(this).parent().parent();

    thanks all!