1
Colleagues,
How would I make the cart calculation not negative. See below:
When I click the button - the quantity remains at 1, but the calculation continues for the negative:
The code I’m using is:
// subtrair quantidade
$('.value-minus').on('click', function(){
var divUpd = $(this).parent().find('.value'), newVal = parseInt(divUpd.text(), 10)-1;
if(newVal>=1) divUpd.text(newVal);
var valorProduto = $(this).closest('tr').find('td[data-nome]').data('nome'); // Funcional
trocar = 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>
It would not be easier just to disable the negative button when it reached 0 items?
– MarceloBoni
Right, but how would I do that? Could you help me?
– user24136
Post the html that generates this layout
– MarceloBoni
I changed the post, put the code that generates the buttons, which are actually Divs and jquery that makes the subtraction effect.
– user24136