Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery parseFloat, parseInt
    primarykey
    data
    text
    <p>I have the following situation, I'm using jquery and I need to sum up some fields on my form. I have found the NaN error in my <strong>subtotal field</strong> and <strong>total field.</strong> I have tried everything possible to avoid this type of error, I just need the SUM on this field. Everything in my form is working fine, only this 2 fields with a problem. I'm using <code>parseFloat()</code> and no response. Only a field with <strong>NaN</strong></p> <p>Follow my javascript code:</p> <pre><code>$(document).ready( function() { $('#valor, #taxa, #imposto, #envio, #taxa_adicional, #subtotal, #total').blur(function(){ // exemplo antigo var val = $('#valor').val(); var val = $('#valor').format({format:"#,###.00", locale:"br"}); var tax = $('#taxa').format({format:"#,###.00", locale:"br"}); var imp = $('#imposto').format({format:"#,###.00", locale:"br"}); var env = $('#envio').format({format:"#,###.00", locale:"br"}); var xat = $('#taxa_adicional').format({format:"#,###.00", locale:"br"}); if(val == "") val = 0; if(tax == "") tax = 0; if(imp == "") imp = 0; if(env == "") env = 0; if(xat == "") xat = 0; var subtotal = parseFloat("val") + parseFloat("tax") + parseFloat("imp") + parseFloat("env"); var total = parseFloat(val) + parseFloat(tax) + parseFloat(imp) + parseFloat(env) + parseFloat(xat); $('#subtotal').format({format:"#,###.00", locale:"br"}); $('#total').val(total); }) }); </code></pre> <p>Thanks in advance for any help on this matter! :-/</p> <p><strong>WARNING:</strong> I'm using a plugin called:<br> <em>jquery.numberformatter - Formatting/Parsing Numbers in jQuery Written by Michael Abernethy</em></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.
 

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