Javascript does not recognize number 10

Asked

Viewed 82 times

2

I got a little problem I don’t know how to fix.

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

Well it works much better 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>

1 answer

4


Just add a parseint() to your $(this). val() and if you want to remove the simple quotes from their value it will also work..

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.