If the number coming from the text box is formatted with vírgula
representing the decimal, it will not work. In javascript, this role is the point .
:
You need to replace the commas with points, and to ensure that you use the parseFloat
function that always returns a number:
function calc() {
var tamanho = parseInt($("#tamanho").val());
var valor = parseFloat($("#valor").val().replace(/\,/, '.'));
var valorMl = valor / tamanho;
console.log(valor, tamanho, valorMl);
}
calc();
$("#tamanho, #valor").on('input', calc);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Tamanho:<inputtype="text" value="350" id="tamanho">
<br>Valor:
<input type="text" value="3,50" id="valor">