Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!