Colleagues,
How would I do to make the calculation of the cart not negative. See below:
When I click the - button the quantity remains at 1, but the calculation continues to negative:
ThecodeI'musingis:
//subtrairquantidade$('.value-minus').on('click',function(){vardivUpd=$(this).parent().find('.value'),newVal=parseInt(divUpd.text(),10)-1;if(newVal>=1)divUpd.text(newVal);varvalorProduto=$(this).closest('tr').find('td[data-nome]').data('nome');//Funcionaltrocar=valorProduto.replace(",",".");
valorTTotal = document.getElementById("total").innerHTML;
trocarSTotal = valorTTotal.replace(",",".");
valorTotal = trocarSTotal - trocar;
if(result == '0.00'){ resultado = result; }else{ resultado = ''; }
document.getElementById("total").innerHTML = valorTotal.toFixed(2) + resultado;
document.getElementById("subtotal").innerHTML = valorTotal.toFixed(2);
$.ajax({
type: "GET",
dataType: 'json',
data:{ valor: valorTotal.toFixed(2) },
url: "atualizar-carrinho.php",
success: function(resposta){
}
});
});
HTML
<td class="invert">
<div class="quantity">
<div class="quantity-select">
<div class="entry value-minus"> </div>
<div class="entry value"><span>1</span></div>
<div class="entry value-plus active"> </div>
</div>
</div>
</td>