Advertisement
petur_stoqnov

Untitled

Jan 27th, 2021
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateReport() {
  2.     let checkBoxInput = Array.from(document.querySelectorAll('input'));
  3.     let row = Array.from(document.querySelectorAll('tbody tr'));
  4.  
  5.     let output = [];
  6.     for (let i = 0; i < row.length; i++) {
  7.         let obj = {}
  8.         for (let j = 0; j < checkBoxInput.length; j++) {
  9.             if(checkBoxInput[j].checked === true){
  10.                 let prop = checkBoxInput[j].parentNode.textContent.trim().toLowerCase();
  11.                 obj[prop] = row[i].children[j].textContent.trim();
  12.             }
  13.         }
  14.         if(Object.keys(obj).length > 0){
  15.             output.push(obj)
  16.         }
  17.     }
  18.     document.querySelector('textarea').value = JSON.stringify(output, null, 2);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement