简体   繁体   English

添加文本框值并在jquery添加行功能的另一个文本框中显示

[英]add text box values and display in another text box in jquery add row function

Please check the link jsfiddle . 请检查链接jsfiddle

Every text box has seperate id. 每个文本框都有单独的ID。

function calculation(id)
{
 var quantity = document.getElementById("qty"+id).value;
 var unit_price = document.getElementById("unit"+id).value;
 var total_price = quantity * unit_price;
 document.getElementById('total_price'+id).value = total_price;
}

I want the sum of total price and display on the final price. 我想要总价的总和并在最终价格上显示。

Thanks in advance 提前致谢

Remove onchange="calculation(id) " call from all inputs and put below jquery function in document.ready 从所有输入中删除onchange="calculation(id) ”调用,并将其放在document.ready中的jquery函数下面

$(document).delegate
('input[id^="qty"],input[id^="unit"]',
 "keyup",function()
{
   var indexVal = $(this).attr('alt');     
   $('#total_price'+indexVal).val(
        $('#qty'+indexVal).val() * $('#unit'+indexVal).val()
    );
  var finalTotalPrice = 0 ;     
   $("input[id^='total_price']").each(function(){
       finalTotalPrice = parseInt(finalTotalPrice) + parseInt($(this).val());
   });
   $("input[name='final_price']").val(finalTotalPrice); 
});

Working JSFiddle 工作JSFiddle

and to show selected discount 并显示选定的折扣

$(document).delegate('select[class="discount"]',"change",function(){
    var discVal = $(this).val();
           $(this).parent().next().children(":nth-child(1)").val(discVal);
});

Working JSFiddle 工作JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM