Z
Z
Zorgios2021-06-09 17:03:28
JavaScript
Zorgios, 2021-06-09 17:03:28

How to collect the names of all active checkboxes from the table into an array for further work with them?

There is a table like

<table id="mainTable">
  <tbody>
    <tr>
      <td>
        <a href=testPath/name1.jpg"><img src="testPath/name1.jpg" alt="" width="100"></a>
        <input type="checkbox" name="testText1" value="testText1">
      </td>
    </tr>
    <tr>
      <td>
        <a href=testPath/name1.jpg"><img src="testPath/name2.jpg" alt="" width="100"></a>
        <input type="checkbox" name="testText2" value="testText2">
      </td>
    </tr>
    ...
    <tr>
      <td>
        <a href=testPath/name1.jpg"><img src="testPath/nameN.jpg" alt="" width="100"></a>
        <input type="checkbox" name="testTextN" value="testTextN">
      </td>
    </tr>
  </tbody>
</table>

In other words. Each row of the table has an image and a checkbox. There can be N number of lines.
How can I collect the values ​​of all active checkboxes from the table, saving their names in an array (for further processing).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-09
@Zorgios

Array.from(document.querySelectorAll('#mainTable input:checked'), n => n.name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question