I set up the function below, for validation of values in two fields, one automatic (comes from the bank) and another one entered by the user. What happens is that apparently he ignores the houses to the right of the value. For example:
function calc_dif() {
if ($(this).val().length > 0) {
qtde = null; //ZERA AS DUAS VARIAVEIS PARA NÃO PEGAR LIXO DA MEMORIA
qtde_trans = null; //ZERA AS DUAS VARIAVEIS PARA NÃO PEGAR LIXO DA MEMORIA
var qtde_trans = $(this).val(); //VALOR DIGITADO
var qtde = $(this).closest('tr').find('[name="qtde[]"]'); //campo ao lado
alert(qtde_trans);
alert(qtde.val());
if (qtde.val() < qtde_trans) {
alert("Não pode transferir mais que o disponível!");
$(this).val(null);
$(this).focus();
qtde = null;
qtde_trans = null;
}
}
}
In the above function, the qtde_trans
field receives the value 50. The qtde
field displays 2000. In the alerts the values are exactly those. But somehow it goes into if, as if qtde
is less. Now, if I type 20, he accepts. But if you type 21 it displays the error. I tried cleaning variables, as above, I tested other methods to compare, but it did not work. Any suggestions?