php - javascript sum returning NaN error -
i have javascript shopping basket, in sum returning nan error,almost every time. in code have
    $('#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 .value').each(function (index, value) {             total += new number($(value));         });          var form = $(this).parents('form');         form.ajaxsubmit(function () {         });          $('#total .value').text(total);     });   i tried using parsefloatm still dosn't work...
$(value) gives jquery-wrapped element, not actual value.
you want $(value).val() instead if elements form inputs, or $(value).text() if not.
also, instead of new number(...) should use number(...), or +...:
$('.product .price .value').each(function (index, value) {     total += +$(value).val(); });   see this question difference between new number , number.
Comments
Post a Comment