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

155
Visualizações
jQuery: count input checked in a table

I'm trying to get the number of machines I selected.

here we have a list of virtual machines and I would like to count the selection that is when I press an input there is the element that is checked.

i tried this but not working.

   $("table input[type=checkbox]").click(function(){
        let nbchecked = $("table input[type='checkbox']:checked").length;
        console.log(nbchecked);
        let len = nbchecked.length;

          $(".counter").html(nbchecked); //inject the number of vm checked in the div
    });

I am a beginner in javascript and jquery and I don't know how to do it. I need your help plz

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

0

It work, post your html plz

$("table input[type=checkbox]").click(function(){
      let nbchecked = $("table input[type='checkbox']:checked").length;
      console.log(nbchecked);
      let len = nbchecked.length;

        $(".counter").html(nbchecked); //inject the number of vm checked in the div
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table" id="vm_table">
  <tbody>
    <tr>
      <td>
        <label for="id_vms_1">
          <input type="checkbox" name="vms" value="12" id="id_vms_1"> vm1
        </label>
      </td>
    </tr>
    <tr>
      <td>
        <label for="id_vms_2">
          <input type="checkbox" name="vms" value="13" id="id_vms_2"> vm2
        </label>
      </td>
    </tr>
    <tr>
      <td>
        <label for="id_vms_3">
          <input type="checkbox" name="vms" value="14" id="id_vms_3"> vm3
        </label>
      </td>
    </tr>
  </tbody>
</table>
<div class="counter"></div>

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