Add and subtract within the same javascript field

0

I need to know, how within an input that in each line returns the value of 0 or 1 (as the case may be), we can add how many 1 and how many 0 there are in total, so we can add and subtract the final value of the amounts to generate a charge based on only 1 for the total of items between them.

I have this table that, as needed, creates more rows to add another product (sales software):

html = '<tr id="tr_'+i+'">';
html += '<td class="" width="50%"><input type="text" data-type="nombre" name="nombre[]" id="nombre_'+i+'"></td>';
html += '<td width="10%"><input type="text" name="cantidad[]" id="cantidad_'+i+'" class="totalCantidad"></td>';
html += '<td width="10%"><input type="text" name="venta[]" id="venta_'+i+'"></td>';
html += '<td class="" width="25%"><input type="text" name="tImp[]" id="tImp_'+i+'" class="tImpLinePrice"></td>';

Then in a function I take out a variable to see which product has 1 or 0:

$('.tImpLinePrice').each(function(){
    if($(this).val() != '' )tImpAmount = parseFloat( $(this).val() );
    subTotalO = tImpAmount;
});
alert(subTotalO); // devuelve 0 o 1

Then next to this other function, view the total of items and perform the calculation:

$('.totalCantidad').each(function(){
    if($(this).val() != '' )cantidad += parseFloat( $(this).val() );
    cantidad1 = cantidad;
});

The problem is that the products that return the 1 have tax and those of 0 do not, and when the function of seeing the total of items (totalQuantity) comes, it passes the total and does not differentiate between 0 and 1 and the gives all for 1 (true) and in the end the tax is charged in general and I just want you to collect those that have value 1

imp = $('#imp').val();
    if(imp != '' && typeof(imp) != "undefined" ){
        impAmount = (cantidad1 * parseFloat(imp));
        $('#impAmount').val(impAmount.toFixed(4));
        total1 = total + impAmount;
    }else{
        $('#impAmount').val(0);
        total1 = total;
    }
$('#totalAfterImp').val( total1 );
calculateAmountDue();

How can I do so that no matter how many lines I add, each time a new item is added, it only works or just executes and adds the tax for those with the value of 1 and not all?

    
asked by Joaquín 30.08.2018 в 18:38
source

0 answers