Advertisement
viligen

travelAgency

Jun 18th, 2022
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.     const allInputs = Array.from(document.querySelectorAll('div#form input'));
  3.     allInputs.pop();
  4.  
  5.     const allLabels = Array.from(document.querySelectorAll('div#form label'));
  6.     const submitBtn = document.querySelector('#submitBTN');
  7.  
  8.     const ul = document.querySelector('#infoPreview');
  9.     const editBtn = document.querySelector('#editBTN');
  10.     const continueBtn = document.querySelector('#continueBTN');
  11.  
  12.     const mainDiv = document.querySelector('#block');
  13.  
  14.     submitBtn.addEventListener('click', function (e) {
  15.         e.preventDefault();
  16.         const inputValues = allInputs.map((x) => x.value);
  17.         if (inputValues[0] == '' || inputValues[1] == '') {
  18.             return;
  19.         }
  20.         submitBtn.disabled = true;
  21.  
  22.         for (let i = 0; i < allInputs.length; i++) {
  23.             let li = document.createElement('li');
  24.             li.textContent = allLabels[i].textContent + ' ' + inputValues[i];
  25.             ul.appendChild(li);
  26.         }
  27.  
  28.         editBtn.disabled = false;
  29.         continueBtn.disabled = false;
  30.         allInputs.forEach((inp) => (inp.value = ''));
  31.  
  32.         editBtn.addEventListener('click', function (e) {
  33.             for (let i = 0; i < allInputs.length; i++) {
  34.                 allInputs[i].value = inputValues[i];
  35.             }
  36.             submitBtn.disabled = false;
  37.             editBtn.disabled = true;
  38.             continueBtn.disabled = true;
  39.             ul.innerHTML = '';
  40.         });
  41.         continueBtn.addEventListener('click', function (e) {
  42.             mainDiv.innerHTML = '<h3>Thank you for your reservation!</h3>';
  43.         });
  44.     });
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement