Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery keeps returning NaN
    primarykey
    data
    text
    <p>I have a function which keeps returning NaN. I've searched the forum and tried everything that I found but obviously I'm doing something wrong seeing my (probably) weird code :)</p> <p>My code:</p> <pre><code> function bakVormTotals(targetClass){ $.getJSON('http://shop.com/cart/?format=json', function(data){ var totaal = 0; $('.grandTotal').each(function(){ //////////// var item = $(this); // FOUND THIS ON FORUM totaal+= parseInt(item.val()); /////////// }) $.each(data.cart.totals, function(index, totals){ $('&lt;strong/&gt;').html('€' + (+totals.grand_total).toFixed(2)).appendTo(targetClass); // the grand total price }); }); } </code></pre> <p>The json looks like this: <code>"totals":{"sub_total":"335.29","taxes":[{"percentage":"0.1900","amount":63.71}],"grand_total":"399.00"}}</code> If that may help. </p> <p>Any help is greatly appreciated</p> <p><strong>UPDATE 1</strong></p> <p>Ok I've found some new interesting stuff. I changed the function above to:</p> <pre><code> function bakVormTotals(targetClass){ $.getJSON('http://shop.com/cart/?format=json', function(data){ $.each(data.cart, function(index, totals){ $('&lt;strong/&gt;').html('€' + totals.grand_total + '').appendTo(targetClass); // the grand total price }); }); } </code></pre> <p>Now the script returns: €undefined€undefined€undefined€undefined€undefined€undefined€undefined€undefined€1197.00</p> <p>Obviously I'm in the right direction since €1197.00 is the correct value. The "undefined" stuff is probably due to the html part?? Can some body help me changing the $('') part to something like "total" so I can leave the HTML part out?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload