mohaammed talha

mohaammed talha

  • NA
  • 445
  • 52.4k

jquery calculation using if and else statement

Nov 23 2021 4:27 PM

How to calculate calculation in jquery using if and else condition

Ex:

function LoadTotal() {
    var $tblrows = $(".costcomplist tbody tr");
    $tblrows.each(function (index) {
        var $tblrow = $(this);
        $tblrow.find('.INRPRICE').on('input', function () {
            var subtotal = 0;
            var tot = 0;
            $('.INRPRICE').each(function () {
                subtotal += parseFloat($(this).val());
            });                      
            var sum =  subtotal;
            $('.total').val(sum.toFixed(2));
            var sellinpri = $tblrow.find('.Component').val();
            if (sellinpri == 'Variable') {
                var subtotal = 0;
                var tot = 0;
                $('.INRPRICE').each(function () {
                    subtotal += parseFloat($(this).val());
                    var subtot = subtotal ;
                    $('.total').val(subtotal.toFixed(2));
                });
            }
            else if (sellinpri == 'Fixed') {
                var subtotal = 0;
                $('.INRPRICE').each(function () {
                    subtotal += parseFloat($(this).val());
                });
                var sell = subtotal ;
                var profit =  sell;
                $('.Profit_loss').val(profit.toFixed(2));
            }
        });
    });
}


Answers (1)