Advertisement
ilianrusev

Untitled

Jan 29th, 2022
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.  
  3. let name = document.getElementById("fname")
  4. let email = document.getElementById("email")
  5. let phone = document.getElementById("phone")
  6. let address = document.getElementById("address")
  7. let code = document.getElementById("code")
  8. let ul = document.getElementById("infoPreview")
  9. let submitBtn = document.getElementById("submitBTN")
  10. let editBtn = document.getElementById("editBTN")
  11. let contBtn = document.getElementById("continueBTN")
  12.  
  13. // submitBtn.type = "button";
  14.  
  15. submitBtn.addEventListener("click", submit)
  16.  
  17. function submit() {
  18. if (name.value != "" && name.value != undefined && email.value != "" && email.value != undefined) {
  19. let liName = document.createElement("li")
  20. liName.textContent = `Full Name: ${name.value}`
  21. let liEmail = document.createElement("li")
  22. liEmail.textContent = `Email: ${email.value}`
  23. let liPhone = document.createElement("li")
  24. liPhone.textContent = `Phone Number: ${phone.value}`
  25. let liAddress = document.createElement("li")
  26. liAddress.textContent = `Address: ${address.value}`
  27. let liCode = document.createElement("li")
  28. liCode.textContent = `Postal Code: ${code.value}`
  29.  
  30.  
  31.  
  32. ul.appendChild(liName)
  33. ul.appendChild(liEmail)
  34. ul.appendChild(liPhone)
  35. ul.appendChild(liAddress)
  36. ul.appendChild(liCode)
  37.  
  38. submitBtn.disabled = true;
  39. editBtn.disabled = false;
  40. contBtn.disabled = false;
  41.  
  42. name.value = ""
  43. email.value = ""
  44. phone.value = ""
  45. address.value = ""
  46. code.value = ""
  47. }
  48. }
  49.  
  50. editBtn.addEventListener("click", edit);
  51.  
  52. function edit() {
  53. let arr = Array.from(ul.children)
  54. for (let i = 0; i < arr.length; i++) {
  55. let value = arr[i].textContent.split(": ")[1]
  56. if (i == 0) {
  57. name.value = value
  58. } else if (i == 1) {
  59. email.value = value
  60. } else if (i == 2) {
  61. phone.value = value
  62. } else if (i == 3) {
  63. address.value = value
  64. } else if (i == 4) {
  65. code.value = value
  66. }
  67.  
  68. arr[i].remove()
  69.  
  70.  
  71. }
  72. submitBtn.disabled = false;
  73. editBtn.disabled = true;
  74. contBtn.disabled = true;
  75.  
  76. }
  77.  
  78. contBtn.addEventListener("click", complete)
  79.  
  80. function complete() {
  81. let main = document.getElementById("block")
  82. let h3 = document.createElement("h3");
  83. h3.textContent = "Thank you for your reservation!"
  84. Array.from(main.children).forEach(e => e.remove())
  85. main.appendChild(h3)
  86. }
  87.  
  88. }
  89.  
Advertisement
RAW Paste Data Copied
Advertisement