2017-07-28 4 views
-1

私は、jqueryを使用してhtmlページの複数の入力値のレコード表示を作成しています2つのクラスの値を減算します。私Jquery 2つの異なるクラス複数の入力テキストの減算を使用して

HTML

<tr> 
    <td><input type="hidden" name="quarter_no[]" value="<?=$value->quarter_no?>">Quarter <?=$value->quarter_no?></td> 
    <td colspan="4"><input type="text" class="form-control" name="receipt_no[]" value="<?=$value->receipt_no?>" placeholder="Quarter1 Recept No."></td> 
    <td><input type="text" class="form-control credited" id="quarter1_amtPaid" name="amount_credited[]" value="<?=$value->amount_credited?>" placeholder="0.00"></td> 
    <td><input type="text" class="form-control deducted" id="quarter1_taxDeducted" name="amount_tax_deduction[]" value="<?=$value->amount_tax_deducted?>" placeholder="0.00"></td> 
    <td><input type="text" class="form-control remitted" id="quarter1_taxRemitted" name="amount_tax_remitted[]" value="<?=$value->amount_tax_remitted?>" placeholder="0.00"></td> 

jqueryの

$(document).ready(function(){ 
    $("body").on("blur", ".credited, .deducted", function(){ 
     var arr = document.getElementsByName('amount_credited[]'); 
     var tot=0; 
     for(var i=0;i<arr.length;i++){ 
      if(parseInt(arr[i].value)) 
       tot += parseInt(arr[i].value); 
     } 
     document.getElementById('quarter1_taxRemitted').value = tot; 

    }); 
    }) 
+0

あなたの質問は正確ですか?何が間違っているかを推測する必要がありますか? – Rubenxfd

答えて

0
<script> 
    $(document).ready(function() { 
     $(".credited , .deducted").on("blur", function() { 
      console.log($('#quarter1_amtPaid').val()); 
      var paid = $('#quarter1_amtPaid').val(); 
      var Deducted = $('#quarter1_taxDeducted').val(); 
      var tot = parseFloat(paid) - parseFloat(Deducted); 
      $('#quarter1_taxDeducted').val(tot); 

     }); 
    }) 
</script> 

はこれを試してみてください助けてください。

関連する問題