Well I edited the question, because I located the problem. I have a javascript responsible for doing calculations with the values in the input, and I have a Jquery Mask or MaskMoney plugin to do the typed value formatting.
Both plugins have the same error.
Jquery Mask - When I type 1.00 the javascript that does the calculation takes the value 100.
MaskMoney - When I type something, the javascript that does the calculation thinks the field is blank.
I need help, please thank you
Follow the code:
$(document).ready(function() {
$(".valor").on("input", function() {
// Margem
var valor = $(this).val();
valor = valor.replace(".", "");
valor = valor.replace(",", ".");
// Custo
var valorCusto = $("#custo").val();
valorCusto = valorCusto.replace(".", "");
valorCusto = valorCusto.replace(",", ".");
var calculo = (parseFloat(valor) - parseFloat(valorCusto)) / parseFloat(valorCusto) * 100;
var inputMargem = $(this).attr("margem");
var resultadoMonetario = calculo.toFixed(2).replace(".", ",");
$("#" + inputMargem).val(resultadoMonetario);
});
$(".margem").on("input", function() {
// Margem
var valorMargem = $(this).val();
valorMargem = valorMargem.replace(".", "");
valorMargem = valorMargem.replace(",", ".");
// Custo
var valorCusto = $("#custo").val();
valorCusto = valorCusto.replace(".", "");
valorCusto = valorCusto.replace(",", ".");
var calculo = (parseFloat(valorCusto) * parseFloat(valorMargem) / 100) + parseFloat(valorCusto);
var inputValor = $(this).attr("valor");
var resultadoMonetario = calculo.toFixed(2).replace(".", ",");
$("#" + inputValor).val(resultadoMonetario);
});
});
$('.valores').mask('00.000.000,00', {
reverse: true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.13.4/jquery.mask.js"></script>
Custo:
<input type='text' id='custo' class='custo valores' name='custo'>
<br>
<br> Valor:
<input type='text' id='valor1' class='valor valores' name='valor1' margem='margem1'> Margem:
<input type='text' id='margem1' class='margem valores' name='margem1' valor="valor1">
<br> Valor:
<input type='text' id='valor2' class='valor valores' name='valor2' margem='margem2'> Margem:
<input type='text' id='margem2' class='margem valores' name='margem2' valor="valor2">
The strange thing is that in the stack it works. Example:
1st cost = 5.55 2nd margin = 1.00 Result = 5.61
Already the same problem code on my page and here: