mohaammed talha

mohaammed talha

  • NA
  • 445
  • 51.3k

How to subtract value in jquery with if condition

Nov 6 2021 2:36 PM

If I select Variable  then subtract (variable & selling Price) 

else if I Select Fixed then subtract (fixed& Contribution)

function LoadTotal() {
 var $tblrows = $(".costcomplist tbody tr");
 $tblrows.each(function (index) {
     var $tblrow = $(this);
         var sellinpri = $tblrow.find('.Component').val();
         if (sellinpri == 'Fixed') {
             var numVal1 = Number($tblrow.find(".INRPRICE").val());
             if (!isNaN(numVal1) && sellinpri == 'Fixed') {
                 $tblrow.find('.INRPRICE').val(numVal1.toFixed(2));
                 var FixedValue = 0;
                 FixedValue += $(this).val();
                 var sellingprice = 200;
                 var Profit_loss = (sellingprice - FixedValue);
                 $('.Profit_loss').val(Profit_loss.toFixed(2));
             }
         }
         else if (sellinpri == 'Variable') {
             var numVal1 = Number($tblrow.find(".INRPRICE").val());
             if (!isNaN(numVal1)) {
                 $tblrow.find('.INRPRICE').val(numVal1.toFixed(2));
                 var grandTotal = 0;
                 $(".INRPRICE").each(function () {
                     var stval = parseFloat($(this).val());
                     grandTotal += isNaN(stval) ? 0 : stval;
                     var sellingprice = 500;
                     var contribution = (sellingprice - grandTotal);
                     $('.Contribution').val(contribution.toFixed(2));
                 });
             }
         }
     });
 });
}

 


Answers (2)