I can not use onkeydown with precision

0

I have the following fields:

WhenIreportthediscountin%,itshouldautomaticallycalculatetheDiscountinR$,andtheresultinthetotalnet,andwhenIinformtheDiscountR$,itgivestheresultinpercentageintheDiscount%field,andtheresultinTotalNet.Uptothatbeauty,I'mdoingthis,buttheresultjustgoespreciselyifIpresstheTABkey,ifIdonotpresstheTABkey,theresultsdonotcomewiththerightdecimalplaces,Iwantedhimtodothat,automatically,withoutpressinganykey,wheretheuser,justtypingthevalue,givestheresultsright.

MyfieldscontainingonKeydownandScript:

<inputtype="number" class="form-control desc_prc" id="Tot_desc_prc" desconto='tot_liquido' placeholder="%" onkeydown="DescontoPorcentagem()" step="00.00" min="0.00">

      <input type="number" class="form-control desc_vlr" id="Tot_desc_vlr" desconto='tot_liquido' placeholder="R$" onkeydown="DescontoReal()" step="00.00" min="0.00">

 <script>
     function DescontoPorcentagem() {
                var bruto = $("#tot_bruto").val();
                var porcentagem = $("#Tot_desc_prc").val();
                var real = $("#Tot_desc_vlr").val();
                var total;
                total = parseFloat((parseFloat(porcentagem) / 100) * parseFloat(bruto));

                $("#Tot_desc_vlr").val(parseFloat(total.toFixed(2)));
                total = parseFloat(bruto) - parseFloat(total);
                $("#tot_liquido").val(parseFloat(total.toFixed(2)));
            }

            function DescontoReal() {
                var bruto = $("#tot_bruto").val();
                var porcentagem = $("#Tot_desc_prc").val();
                var real = $("#Tot_desc_vlr").val();
                var total;
                total = parseFloat(bruto) - parseFloat(real)
                $("#tot_liquido").val(parseFloat(total.toFixed(2)));
                total = (real / bruto) * 100
               }
 </script>
    
asked by anonymous 05.09.2017 / 14:57

0 answers