Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
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>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Please check the two lines of your code , without them it works fine :

$('#user_type').on('change', function() {
      if ($(this).val() == 6) {
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda