jquery parameters synchronisation
i have written a shopping basket using js, and i am updating the total sum of the basket automatically when one selects a quantity. my problem is that, when i drop a product, the total value of the sum does not update but on page refresh.
here is the code:
$('#add-to-basket select').selectbox();
$('#contents select').selectbox().change(function (e) {
var product = $(this).parents('.product');
var ppu = product.find('.ppu').val();
product.find('.price .wrapper .value').text($(this).val() * ppu);
var total = 0;
$('.product .price .开发者_StackOverflow社区value').each(function (index, value) {
total += +$(value).text();
});
var form = $(this).parents('form');
form.ajaxSubmit(function () {
});
$('#total .value').text(total);
$('#my_basket .basket_value').text(total);
});
$('#delivery #address a').qtip({
content: 'Vei putea reveni la coș dând click pe <span>Coșul Meu</span> în meniu.'
});
$('.drop-item').click(function(e) {
e.preventDefault();
var form = $(this).parents(form);
var item = $(this).parents('li');
var total = 0;
$('.product .price .value').each(function (index, value) {
total += +$(value).text();
});
$('#total .value').text(total);
item.remove();
form.ajaxSubmit(function() {});
if ($('#contents li').length < 1)
{
$('#basket').remove();
$('#basket-breadcrumbs').remove();
$('#main').append('<p class="message">Coșul tău este gol.</p>');
}
});
my problem is at the removing item feature. how can i make the total value update on item remove?
thank you!
From what I can see you probably just need to move your item.remove()
call up a few lines inside of your .drop-item click handler. You need to make sure you remove the item from the DOM before you retrieve the new list of inputs that you're going to total up.
精彩评论