Good friends, I have a problem, the if does not work correctly for me, I have an input type number which I must enter an amount greater than 0 and less than the maximum established, but if I meet those conditions correctly it still throws the conditional as invalid and goes to the else, any help I appreciate. enter image description here
//VERIFICACION DE VALORES PARA BOTON DE SEND COSECHA
$(document).on('keyup', '.cantCosecha', function () {
let cant = $(this).val(); //VALOR DEL INGRESO
let max = $(this).attr('max'); //ATRIBUTO AGREGADO AUTO QUE ES 1000 EN ESTE CASO
console.log(cant); //CANTIDAD QUE INGRESO
console.log(max); //ESTA CANTIDAD ES 1000
if (cant <= max && cant > 0 && cant.length > 0) { //CONDICION POSITIVA LA CUAL ME PERMITE SEGUIR CON LA COSECHA
$('.stopCosecha').css("display","none")
$('.sendCosecha').css("display","flex")
$(".sendCosecha").css("background-color", "green");
} else { // CONDICION NEGATIVA
$('.stopCosecha').css("display","flex")
$('.sendCosecha').css("display","none")
$(".sendCosecha").css("background-color", "red");
}
});
// HTML
<input type="number" value="" class="boton-cultivo cantCosecha" min="1" max="${cantidad}" Placeholder="Cantidad de la Cosecha">
<i class="fas fa-check boton-cultivo sendCosecha" id="sendCosecha" cantidad="${cantidad}" vegetal="${idVegetal}" variedad="${idVariedad}"></i>
<i class="fas fa-times boton-cultivo stopCosecha"></i>
The attributes are read as a string, therefore you are comparing (highest and lowest) against string's, I have no idea of the javascript logic for these cases, but I guess it has to do with the conversion to ASCII, similar to what happens in the alphanumeric sorting
You must convert your attributes to Number
Also remove the cant.length which doesn't make sense now that it's Number