Convert not selected checkboxes row in html table to javascript array

Hi,
I’ve got a HTML table and for each row I’ve got a checkbox, some cells with text and a cell with a input field, I need to convert all the rows except the one selcted into a javascript array so I can then pass the array to ajax and process with PHP.

This is what I’ve done so far

                var TableData = new Array();

                $('.kmg_admin_millesimal_buildings_table tr').each(function (row, tr) {

                    TableData[row] = {

                      "Codice": $(tr).find('td:eq(1)').text(),
                      "Piano": $(tr).find('td:eq(2)').text(),
                      "Interno": $(tr).find('td:eq(3)').text(),
                      "Millesimi": $(tr).find('td').eq(4).find('input').val()
                   
                    }

                });

                TableData.shift(); // remove header
                TableData.pop(); // remove last object from array

                console.log(TableData);

I tried change the following

$('.kmg_admin_millesimal_buildings_table tr').each(function (row, tr)

With the following


$(".kmg_admin_millesimal_buildings_table tr").find('input[type=checkbox]').not(':checked').each(function (row, tr)

But it doesn’t select only the not selected checkboxes. Any idea how to fix it? Many thanks

This is my how my table looks like:
15

Make it a single selector; saves yourself time, and the browser processing.

$(".kmg_admin_millesimal_buildings_table input[type=checkbox]:not(:checked)")

(the row, then, is element.parent().parent() assuming you havent wrapped the checkboxes in anything other than a td inside the tr)

Hi @m_hutley I’ve tried to edit the code in this way, but it doesn’t work, what am I doing wrong?

                var TableData = new Array();

                $('.kmg_admin_millesimal_buildings_table tr input[type=checkbox]:not(:checked)').each(function (row, tr) {
                
                    TableData[row] = {

                      "Codice": $(tr).find('td:eq(1)').text(),
                      "Piano": $(tr).find('td:eq(2)').text(),
                      "Interno": $(tr).find('td:eq(3)').text(),
                      "Millesimi": $(tr).find('td').eq(4).find('input').val()
                   
                    }

                });

                TableData.shift();
                TableData.pop();

                console.log(TableData);

That.