Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting NaN as result of a calculation from data that was dynamically created
    primarykey
    data
    text
    <p>Hi I'm having problems with updating results of a calculation using the change method.</p> <p>The calculation is made from dynamically created data that is placed into a table row. so the last column of each row should show the total of the price * qty (qty is derived from dynamically created select element). The way to create each row is by selecting an option from the auto-complete input box.</p> <p>Every time the user select the option from the select element that is in a dt ,the total of that row should be updated. it works the first time but the second time the result column turn to NaN.</p> <p><a href="http://jsfiddle.net/49axJ/3/" rel="nofollow"><strong><em>jSfiddle</em></strong></a></p> <p>I think i might have problems with how I set up the rows with the</p> <pre><code> $("tr").not(":first").each(function(){// meant to not get the header but the rest of the rows which have the data for the calculations </code></pre> <p>or the math part. i subtracted 0 from a string to make that into a number so I think I shouldn't get NaN. I know i messed up something that prob seems obvious to you but def not to me.</p> <blockquote> <pre><code> $("tr").not(":first").each(function(){ var qnty = 0; $('select').change(function(){ qnty = $('select').val(); calcTotal(); }) function calcTotal(){ var price = (($(".price").text()) - 0).toFixed(2) $(".total").text(qnty * price); } }) </code></pre> </blockquote> <p>To sum up the problem. the calculations don't work starting from the second time the row with data is created. The result in the result column is NaN. I would obviously like the result to be the calculation of qnty * price for each row in the Total column.</p> <p>Here the <a href="http://jsfiddle.net/49axJ/3/" rel="nofollow"><strong><em>jSfiddle</em></strong></a> to illustrate my problem.</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.
    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