1

I have a jsFiddle to demonstrate my issue (and allow you guys to straighten me out).

I'm simply checking the values of two input textboxes and alerting the user if the max price is less than the minimum price, but they're evaluating backwards! I have if (maxValue < minValue)... but it evaluates it as if the operator is "is greater than".

What am I missing?!?

<form id="search" action="search.php" method="post">

    <label id="lblPriceMin" for="txtPriceMin">Minimum Price</label>
    <input type="text" id="txtPriceMin" name="priceMin"></input>
    <br />
    <br />

    <label id="lblPriceMax" for="txtPriceMax">Maximum Price</label>
    <input type="text" id="txtPriceMax" name="priceMax"></input>
    <br />
    <br />

    <input type="reset" id="reset" name="reset" value="Clear Form" />
</form>

Here's the js,

$('#txtPriceMax').focusout(function() {

    var minValue = $('input#txtPriceMin').val();
    var maxValue = $('input#txtPriceMax').val();

    //alert ('minValue: ' + minValue + ', maxValue: ' + maxValue);

    if (maxValue < minValue) {
        alert ('The maximum value (' + maxValue + ') must be greater than the minimum value (' + minValue + ')!');
    }
});
Jashwant
  • 28,410
  • 16
  • 70
  • 105
marky
  • 4,878
  • 17
  • 59
  • 103
  • possible duplicate of [Unexpected result from "greater than" comparison of values from a text input](http://stackoverflow.com/questions/8475846/unexpected-result-from-greater-than-comparison-of-values-from-a-text-input) –  Aug 08 '12 at 18:43

1 Answers1

8

Use parseFloat()

jsFiddle Example

if (parseFloat(maxValue) < parseFloat(minValue)) 
Gabe
  • 49,577
  • 28
  • 142
  • 181