Advertisement
Guest User

Untitled

a guest
May 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let inputTextArea = document.querySelector('textarea');
  3.     let productsTable = document.querySelector('tbody');
  4.  
  5.     let generateButton = document.querySelector('button');
  6.     generateButton.addEventListener('click', function () {
  7.         let object = JSON.parse(inputTextArea.value);
  8. // creates new row
  9.         let newTrElement = document.createElement('tr');
  10.         productsTable.appendChild(newTrElement)
  11.  
  12. // creates a cell for the image
  13.         let imageTd = document.createElement('td');
  14.         let image = document.createElement('img');
  15.         image.src = object[0].img;
  16.         imageTd.appendChild(image);
  17.  
  18.         newTrElement.appendChild(imageTd);
  19.  
  20. //creates a cell for the name
  21.         let nameTd = document.createElement('td');
  22.         let name = document.createElement('p');
  23.         name.innerText = object[0].name;
  24.         nameTd.appendChild(name);
  25.  
  26.         newTrElement.appendChild(nameTd);
  27.  
  28. //creates a cell for the price
  29.         let priceTd = document.createElement('td');
  30.         let price = document.createElement('p');
  31.         price.innerText = object[0].price;
  32.         priceTd.appendChild(price);
  33.  
  34.         newTrElement.appendChild(priceTd);
  35.  
  36. //creates a cell for the decFaftor
  37.         let decfacTd = document.createElement('td');
  38.         let decfact = document.createElement('p');
  39.         decfact.innerText = object[0].decFactor;
  40.         decfacTd.appendChild(decfact);
  41.  
  42.         newTrElement.appendChild(decfacTd);
  43.  
  44. //creates a checkable checkbox..the default one isn`t
  45.         let checkBoxTd = document.createElement('td');
  46.         let checkBox = document.createElement('input');
  47.         checkBox.type = 'checkbox';
  48.         checkBox.disabled = false;
  49.         checkBoxTd.appendChild(checkBox);
  50.  
  51.         newTrElement.appendChild(checkBoxTd);
  52.     })
  53.  
  54.    
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement