1

I'm very new to jquery and javascript, and I'm hoping anyone can help me find out how to count number of rows that has all their checkboxes checked.

I have a checkbox form with dynamic amount of rows and 3 checkboxes on each row. What I want to find out is how many rows that has all the 3 checkboxes checked. All the rows has id tr0, tr1, tr2 ...

This is what I have so far, it checks the first row (tr0) in my form and alerts "1" if all the boxes are checked in that row after you submit your table. When testing I have 3 tr rows + 1 header.

$(function howManyAreChecked() {
  var checkedBoxes = 0;
  //when the submit button under the table is clicked
  $("#tabellSubmit").click(function howMany() {
    var rowCount = $('#qaTabell tr').length;

    //checks if row tr0 has all the boxes checked
    if($("#qaTabell #tr0 input:checked").length > 2) 
      checkedBoxes = checkedBoxes +1;

  alert(checkedBoxes);
  checkedBoxes = 0; 
  });
});

What I need to know is how I can change the if-test to check tr0, tr1, tr2, tr3... up to tr(number of rows in the table) instead of only tr0.

Thanks in advance!

meisu
  • 11
  • 2
  • I'm very new to this so Im a bit confused how that can help me. I have a table with a submit button at the end. When you click the submit button the function howManyAreChecked() starts and counts how many rows that has all the boxes checked. What I need to know is how to find out how many rows I have, and change the if-test to check tr0, tr1, tr2, tr3... up to tr(number of rows in the table) instead of only tr0. – meisu Nov 24 '14 at 21:18

1 Answers1

0

You have to use .on() to take into account the rows which have not been created yet since they are dynamic.

$("#tabellSubmit").on('click', function(){});

jQuery .on() reference

Anubhav
  • 7,138
  • 5
  • 21
  • 33
  • I edited my post, but #tabellSubmit is the submit-button that shows up after the table is loaded, so I haven't had a problem with that yet. – meisu Nov 24 '14 at 20:57