Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add array of numbers with thousand separators in jquery?
    primarykey
    data
    text
    <p>Ok i have this table where the last column is a number only column and is formatted with thousand separators and decimal. Here's a sample code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="jquery.js"&gt;&lt;/script&gt; &lt;script src="includes/autoNumeric.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { jQuery(function($) { $('input.auto').autoNumeric(); }); $("#table").keyup(function(){ var sal_total = 0; $(".salary[value!='']").each(function() { sal_total += Number($(this).val()); }); $('#total').val(sal_total); }); $("#addRow").click(function() { var newRow = "&lt;tr&gt;&lt;td&gt;&lt;input type=\"text\"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=\"text\"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=\"text\" class=\"auto salary\"&gt;&lt;/td&gt;&lt;/tr&gt;"; $("#table tr.totalRow:last").before(newRow); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="table" border="1"&gt; &lt;tr&gt; &lt;td&gt;ID&lt;/td&gt; &lt;td&gt;Name&lt;/td&gt; &lt;td&gt;Salary&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" &gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" &gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="auto salary"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" &gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" &gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="auto salary"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" &gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" &gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="auto salary"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt;Total&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="total" readonly="readonly" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div align="center"&gt; &lt;input type="button" id="addRow" value="Add Row" /&gt; &lt;input type="submit" name="save" value="Save" /&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The salary column is automatically formatted with autoNumeric plugin to insert comma every thousand and put decimal point, i would like to add those salary values every keypress and put the sum in input#total. It works when i remove the commas but produces NaN when there is, plus whenever i add a row autoNumeric does not work on that particular row. Please help I'm just a newbie on this.</p>
    singulars
    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.
    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