4
I set the function below, for validation of values in two fields, one automatic (comes from the bank) and the other typed by the user. What happens is that, apparently, it 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 function above, the field qtde_trans
value 50. The field qtde
displays 2000. In Alerts the values are exactly those. But somehow it enters the if, as if the qtde
was smaller. Now, if I type 20, it accepts. But if you type 21 it displays the error. I tried to clear variables, as it is above still, I tested other methods to compare, but it did not take effect. Any suggestions?
Have you tried converting to Number both? Number($(this).val()) ? Oh, and also, made sure that there is no more than one field named Qtde[]?
– Aline
Thanks, I just put the Number in both, it worked. There is only one field with the name Qtde. You can post as reply :)
– Diego