Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda