I’m meeting a strange thing…
I’ve a form validated with jquery validator.
I’ve to compare two fields (only numerics), one has to be greater than the other one.
here’s what I do:
$.validator.addMethod("oneGreaterThanTwo", function(value, element) {
return $('#one').val() >= $('#two').val();
}, "One has to be greater than two");
It’s working fine until I use numbers greater than 10…
For example if I put 9 and 4, no problem, If I put 4 and 9 I’ve my error message “One has to be greater than two” displayed.
But if I put 11 and 4 I’ll have the error message displayed until I put a number smaller that 10….
Anyone has an idea?
The
.val()method returns a string, so even though they’ll represent numbers, they’ll be compared alphabetically rather than numerically. Use the JavascriptparseInt()method to convert them to numbers, then compare them.