0

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!

9
  • 2
    Is $(".input-text") an unique element? Commented May 3, 2013 at 16:27
  • 2
    var value = $(".input-text").val(); if(value > x && value < y){}? Commented May 3, 2013 at 16:27
  • Do you want to execute the mentioned function whenever the value of the textbox changes? Commented May 3, 2013 at 16:28
  • You need to parse the value for numerical comparison:- parseFloat($(".input-text").val(),10) > 499 Commented May 3, 2013 at 16:29
  • @roasted yes its a unique element, i can always trail it down to the exact element in case Commented May 3, 2013 at 16:31

2 Answers 2

5

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) {}
Sign up to request clarification or add additional context in comments.

Comments

0

Do

$(".input-text").change(function() {
    if (this.value > 499 && this.value < 1000) {
        console.log("working");
    }
});

Demo: http://jsfiddle.net/XZ4dq/

1 Comment

This worked for what i needed best, thanks a lot. I was able to set multiple to work for different ranges, thanks agin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.