Advertisement
dimitaryodimitrov

Untitled

Jan 29th, 2022
770
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateReport() {
  2.     let checkboxElements = Array.from(document.querySelectorAll('input[type="checkbox"]'));
  3.     let trElements = document.querySelectorAll('tbody tr')
  4.  
  5.     let checkedElements = [];
  6.  
  7.     for (let i = 0; i < checkboxElements.length; i++) {
  8.         if (checkboxElements[i].checked) {
  9.             checkedElements.push([checkboxElements[i].name, i]);
  10.         }
  11.     }
  12.  
  13.     let arrResult = [];
  14.  
  15.     for (let i = 0; i < trElements.length; i++) {
  16.         let objElements = {};
  17.  
  18.         for (let j = 0; j < checkedElements.length; j++) {
  19.             objElements[checkedElements[j][0]] = trElements[i].cells[checkedElements[j][1]].textContent;
  20.         }
  21.  
  22.         arrResult.push(objElements);
  23.     }
  24.  
  25.     let resultElement = document.getElementById('output');
  26.     resultElement.value = JSON.stringify(arrResult, null, ' ');
  27. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement