I have a weird problem with some operations. I'm trying to calculate total items quantity just like shopping carts but sometimes the result shown is a Nan.
var thisID = $(this).attr('id');
var itemname = $(this).find('div .name').html();
var itemprice = $(this).find('div .price').html();
if (include(Arrays, thisID)) {
var price = $('#each-' + thisID).children("li").children(".shopp-price").find('em').html();
var quantity = $('#each-' + thisID).children("li").children(".shopp-quantity").html();
quantity = parseInt(quantity) + parseInt(1);
var total = (parseFloat(itemprice) * parseFloat(quantity)).toFixed(2);
$('#each-' + thisID).children("li").children(".shopp-price").find('em').html(total);
$('#each-' + thisID).children("li").children(".shopp-quantity").html(quantity);
var prev_charges = $('.cart-total').html();
prev_charges = parseFloat(prev_charges) - parseFloat(price);
prev_charges = (parseFloat(prev_charges) + parseFloat(total)).toFixed(2);
$('.cart-total').html(prev_charges);
qte = prev_charges;
}
The problem is sometimes it shows well and other times not. I am wondering if this is a parseFloat() or parseInt() issue. Here is a screenshot https://www.screencast.com/t/B4LtcaOD6J5