jquery: i have to use parseInt() even when deal with numbers, why?

Posted by Syom on Stack Overflow See other posts from Stack Overflow or by Syom
Published on 2010-05-29T18:34:44Z Indexed on 2010/05/29 18:42 UTC
Read the original article Hit count: 147

Filed under:
|

i have the following script

<select id="select1">
      <option value="1">1day</option>
      <option value="2">2day</option>
      <option value="3">3day</option>
    </select>

    <select id="select2">
      <option value="1">1day</option>
      <option value="2">2day</option>
      <option value="3">3day</option>
    </select>

and jquery

$("#select2").change(function() {
            var max_value = parseInt($("#select2 :selected").val());
            var min_value = parseInt($("#select1 :selected").val());
            if(max_value < min_value)
            {
              $("#select1").val($(this).val());
            }
        });

and now, what i can't understand anyway - if values of option elements are integer numbers, why i have to use parseInt()? in some cases it doesn't work without parseInt().

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery