JavaScript does not recognize number 10

2

I have a problem that I do not know how to solve.

In this code below it does the following .... according to a drop down with values from 0 to 10
being that the selected option is less than 8 it shows a hidden div, if larger form does nothing.

Well it works very well more until the number 9 if you choose in the dropdown the number 10 it shows the hidden div

   <select name="pes11" id="privileges1" class=""        
   onclick="craateUserJsObject.ShowPrivileges();">
   <option value=""></option>
   <option value="1">1</option>  --> ok 
   <option value="2">2</option>  --> ok
   <option value="3">3</option>  --> ok
   <option value="4">4</option>  --> ok
   <option value="5">5</option>  --> ok
   <option value="6">6</option>  --> ok
   <option value="7">7</option>  --> ok
   <option value="8">8</option>  --> ok
   <option value="9">9</option>  --> ok
   <option value="10">10</option> --> ERRO acho que reconhece o 10 como 1
   </select>
   <script>
   var Privileges = jQuery('#privileges1');
   var select = this.value;Privileges.change(function () {
   if ($(this).val() < '8') {
   $('.txt').show();
   }
   else $('.txt').hide();
   });
   </script>

   <div class="txt" style=" display: none;">
   </div>
    
asked by anonymous 16.08.2015 / 04:23

1 answer

4

Just add a parseInt () to your $ (this) .val () and if you want to remove the single quotation marks from its value will also work ..

var Privileges = jQuery('#privileges1');
var select = this.value;

Privileges.change(function () {
   if (parseInt($(this).val()) < 8) {
        $('.txt').show();
   } else { 
       $('.txt').hide();
   }
});
    
16.08.2015 / 04:40