Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function generateReport() {
- let results = [];
- let checkedBoxes = {};
- const totalBoxes = Array.from(document.querySelectorAll('table thead tr th')).map(x => x.children[0]);
- for (let i = 0; i < totalBoxes.length; i++) {
- const box = totalBoxes[i];
- if (box.checked) {checkedBoxes[i] = box.name}
- }
- const rows = Array.from(document.querySelectorAll('table tbody tr')).map(x => Array.from(x.children));
- for (let row of rows) {
- let obj = {};
- for (let i = 0; i < row.length; i++) {if (Object.keys(checkedBoxes).map(Number).includes(i)) {obj[checkedBoxes[i]] = row[i].textContent;}}
- results.push(obj);
- }
- document.getElementById('output').textContent = JSON.stringify(results);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement