0
I have the following fields:
When I inform the discount in %, it must automatically calculate the Discount in R$, and the result in the total liquid, and when I inform in the Discount R$, it gives the result in percentage in the Discount %, and the result in the Total Liquid. Until then beauty, I’m doing it, but the result only goes accurately if I press the key TAB
, if I don’t press the button TAB
, the results do not come with the right decimal places, I wanted him to do it, automatically, without having to press any key, where the user, just typing the value, he gave the right results.
My fields where it contains the onKeydown
and the Script
:
<input type="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>
Are you sure that code is enough to simulate the problem?
– Gabriel Rodrigues
That’s what I’m wearing right now
– Alysson bormann