0

Please check the link jsfiddle.

Every text box has seperate 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

1 Answer 1

2

Remove onchange="calculation(id)" call from all inputs and put below jquery function in document.ready

$(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

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

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer but i need is if i add another row and do the same the sum of the total price will be displayed on final price text box
hi @Bhushan i need your help please see the updated jsfiddle. when i change the select box the value will be displayed on the percentage text box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.