Reputation: 41
Im trying to use jquery to detect a number above or below:
$(".input-text").val()) > 499) {}
$(".input-text").val()) < 1000) {}
Is there a way to set a range such as 500-1000 and the having jquery execute a function based on the range?
Thanks in advance!
Upvotes: 0
Views: 189
Reputation: 494
You need to parse the input because it is just a string not a number
If your input is just Int:
if(parseInt($(".input-text").val(),10) > 499) {}
if(parseInt($(".input-text").val(),10) < 1000) {}
If your input is Float:
if(parseFloat($(".input-text").val(),10) > 499) {}
if(parseFloat($(".input-text").val(),10) < 1000) {}
Upvotes: 5
Reputation: 104775
Do
$(".input-text").change(function() {
if (this.value > 499 && this.value < 1000) {
console.log("working");
}
});
Demo: http://jsfiddle.net/XZ4dq/
Upvotes: 0