petur_stoqnov

Untitled

Jan 24th, 2021
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateReport() {
  2.     let employee = document.querySelector('input[name="employee"]');
  3.     let department = document.querySelector('input[name="deparment"]');
  4.     let status = document.querySelector('input[name="status"]');
  5.     let hireDate = document.querySelector('input[name="dateHired"]');
  6.     let benefits = document.querySelector('input[name="benefits"]');
  7.     let compensation = document.querySelector('input[name="salary"]');
  8.     let rating = document.querySelector('input[name="rating"]');
  9.  
  10.     let row = document.querySelectorAll('tbody>tr');
  11.  
  12.     let output = [];
  13.     for (let i = 0; i < row.length; i++) {
  14.         let obj = {}
  15.         if (employee.checked === true) {
  16.             let employeeValue = row[i].getElementsByTagName('td')[0].textContent;
  17.             obj.employee = employeeValue;
  18.         }
  19.         if (department.checked === true) {
  20.             let departmentValue = row[i].getElementsByTagName('td')[1].textContent;
  21.             obj.deparment = departmentValue;
  22.         }
  23.         if (status.checked === true) {
  24.             let statusValue = row[i].getElementsByTagName('td')[2].textContent;
  25.             obj.status = statusValue;
  26.         }
  27.         if (hireDate.checked === true) {
  28.             let hireDateValue = row[i].getElementsByTagName('td')[3].textContent;
  29.             obj.hireDate = hireDateValue;
  30.         }
  31.         if (benefits.checked === true) {
  32.             let benefitsValue = row[i].getElementsByTagName('td')[4].textContent;
  33.             obj.benefits = benefitsValue;
  34.         }
  35.         if (compensation.checked === true) {
  36.             let compensationValue = row[i].getElementsByTagName('td')[5].textContent;
  37.             obj.compensation = compensationValue;
  38.         }
  39.         if (rating.checked === true) {
  40.             let ratingValue = row[i].getElementsByTagName('td')[6].textContent;
  41.             obj.rating = ratingValue;
  42.         }
  43.  
  44.         if (Object.keys(obj).length > 0) {
  45.             output.push(obj)
  46.         }
  47.     }
  48.    
  49.     document.querySelector('#output').value = JSON.stringify(output, null, 2);
  50. }
RAW Paste Data