I have two textboxes, with that am trying to validate like
var max = $("#txtMaximumMark").val()
var min = $("#txtMinimumMark").val();
var valid = max > min;
if I give 10 as minimun and 100 as maximum, it shows the given value is valid, but if I give 40 as minimum and 100 as maximum, the valid returns false, whats goin on here, why it returns false, can anyone help me here…
Because it’s comparing
strings. Using.val()returns strings, so when you compare them, it compares them as strings.In strings, 4 is higher than 1, so 40 is higher than 100 (like
ais higher thanbaaa).To do your comparison correctly, use
parseIntto cast your strings to integers: