mercredi 5 janvier 2022

I have to Iterate thorough check boxes if the value of checkbox is in my array I want the check box to be checked

This is my function and it is not working, My check boxes remain unchecked

$(document).ready(function() {
        var sales_agent_prev_arr = ['21-1', '21-2', '21-3', '21-5', '21-6', '26-1', '26-2', '26-3', '8-1', '8-9', '8-2', '8-3', '8-4', '8-5', '13']
        $('#user_type').on('change', function() {
          if ($(this).val() == 6) {
            $('input[type="checkbox"]').each(function() {
              if ($.inArray(this.value, sales_agent_prev_arr) !== -1) {
                $(this).prop('checked',true);
              }
            });
          }
        })
      });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li><input type="checkbox" value="21-1">View All</li>
  <li><input type="checkbox" value="21-2">check</li>
</ul>



Aucun commentaire:

Enregistrer un commentaire