eternalmeg

generateReport

May 26th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function generateReport() {
  2. let inputElements = Array.from(document.getElementsByTagName('input'));
  3.  
  4. const resultArr = [];
  5. let tableRows = Array.from(document.getElementsByTagName('tr'));
  6. const checkedCols = [];
  7.  
  8. for (let i = 0; i < tableRows.length; i++) {
  9. const row = tableRows[i];
  10. const obj = {};
  11.  
  12. for (let y = 0; y < row.children.length; y++) {
  13. const element = row.children[y];
  14. if (i == 0) {
  15. if (element.children[0].checked) {
  16. checkedCols.push(y);
  17. }
  18. continue;
  19. }
  20.  
  21. if (checkedCols.includes(y)) {
  22. let propertyName = inputElements[y].name;
  23. obj[propertyName] = element.textContent;
  24. }
  25. }
  26. if (i !== 0) {
  27. resultArr.push(obj);
  28. }
  29. }
  30.  
  31. document.getElementById('output').value = JSON.stringify(resultArr);
  32. }
Add Comment
Please, Sign In to add comment