Advertisement
stsp93

Untitled

Oct 15th, 2022
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. function solution() {
  2. const fullNameIn = document.querySelector('#fname');
  3. const emailIn = document.querySelector('#email');
  4. const phoneIn = document.querySelector('#phone');
  5. const addressIn = document.querySelector('#address');
  6. const postalIn = document.querySelector('#code');
  7. const submitBtn = document.querySelector('#submitBTN');
  8.  
  9. const infoPreviewUl = document.querySelector('#infoPreview');
  10. const editBtn = document.querySelector('#editBTN');
  11. const continueBtn = document.querySelector('#continueBTN');
  12. const blockDiv = document.querySelector('#block');
  13.  
  14.  
  15.  
  16. function submit(e) {
  17. e.preventDefault();
  18. const name = fullNameIn.value;
  19. const email = emailIn.value;
  20. const phone = phoneIn.value;
  21. const address = addressIn.value;
  22. const postal = postalIn.value;
  23.  
  24. if (name === '' || email === '') return;
  25.  
  26. const nameLi = document.createElement('li');
  27. nameLi.textContent = 'Full Name: ' + name
  28. const emailLi = document.createElement('li')
  29. emailLi.textContent = 'Email: ' + email
  30. const phoneLi = document.createElement('li')
  31. phoneLi.textContent = 'Phone Number: ' + phone
  32. const addressLi = document.createElement('li')
  33. addressLi.textContent = 'Address: ' + address;
  34. const postalLi = document.createElement('li')
  35. postalLi.textContent = 'Postal Code: ' + postal;
  36.  
  37. infoPreviewUl.appendChild(nameLi);
  38. infoPreviewUl.appendChild(emailLi);
  39. infoPreviewUl.appendChild(phoneLi);
  40. infoPreviewUl.appendChild(addressLi);
  41. infoPreviewUl.appendChild(postalLi);
  42.  
  43. fullNameIn.value = '';
  44. emailIn.value = '';
  45. phoneIn.value = '';
  46. addressIn.value = '';
  47. postalIn.value = '';
  48.  
  49. submitBtn.disabled = true;
  50. editBtn.disabled = false;
  51. continueBtn.disabled = false;
  52.  
  53. editBtn.addEventListener('click', function () {
  54. fullNameIn.value = name;
  55. emailIn.value = email;
  56. phoneIn.value = phone;
  57. addressIn.value = address;
  58. postalIn.value = postal;
  59.  
  60. submitBtn.disabled = false;
  61. editBtn.disabled = true;
  62. continueBtn.disabled = true;
  63.  
  64. nameLi.remove();
  65. emailLi.remove();
  66. phoneLi.remove();
  67. addressLi.remove();
  68. postalLi.remove();
  69. })
  70.  
  71.  
  72. continueBtn.addEventListener('click', function () {
  73. for(let el of Array.from(blockDiv.children)){
  74. el.remove();
  75. }
  76.  
  77. const h3 = document.createElement('h3');
  78. h3.textContent = 'Thank you for your reservation!'
  79. blockDiv.appendChild(h3)
  80. })
  81. }
  82.  
  83.  
  84.  
  85. submitBtn.addEventListener('click', submit)
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement