Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like you're using this plugin: <a href="http://code.google.com/p/jquery-numberformatter/" rel="nofollow">http://code.google.com/p/jquery-numberformatter/</a></p> <p>That plugin will take an element, parse the value according to the format, and reinsert it into the DOM, from what I can tell. So I'm going to assume that's the case.</p> <pre><code>$(document).ready( function() { $('#valor, #taxa, #imposto, #envio, #taxa_adicional, #subtotal, #total').blur(function(){ /* // first update all fields to have the correct format, so we can work with them later. $('#valor').format({format:"#,###.00", locale:"br"}); $('#taxa').format({format:"#,###.00", locale:"br"}); $('#imposto').format({format:"#,###.00", locale:"br"}); $('#envio').format({format:"#,###.00", locale:"br"}); $('#taxa_adicional').format({format:"#,###.00", locale:"br"}); */ //separating because I'm pretty sure this would work in place of all those lines of code: // needs testing though. If this doesn't work uncomment the previous block and delete this line $('#valor,#taxa,#imposto,#envio,#taxa_adicional').format({format:"#,###.00", locale:"br"}); // then since the values have been formatted, let's extract just the floats like you wanted // going through the document.getElementById since the jQuery wrapper is useless overhead and you don't need a jQuery object back out. var val = parseFloat( document.getElementById('val').innerHTML ); var tax = parseFloat( document.getElementById('taxa').innerHTML ); var imp = parseFloat( document.getElementById('imposto').innerHTML ); var env = parseFloat( document.getElementById('envio').innerHTML ); var xat = parseFloat( document.getElementById('taxa_adicional').innerHTML ); if( isNaN( val ) ) val = 0; if( isNaN( tax ) ) tax = 0; if( isNaN( imp ) ) imp = 0; if( isNaN( env ) ) env = 0; if( isNaN( xat ) ) xat = 0; var subtotal = val + tax + imp + env; var total = val + tax + imp + env + xat; $('#subtotal').val(subtotal).format({format:"#,###.00", locale:"br"}); $('#total').val(total).format({format:"#,###.00", locale:"br"}); }); }); </code></pre> <p>Notice that I am only trying to help you have easier to read code. There are probably lots of ways to write this to get it <em>leaner[1]</em> </p> <p><br /></p> <p>[1] less fat; less waste; ~ Perhaps this translates, perhaps it is an idiom?</p>
 

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