Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution() {
- const allInputs = Array.from(document.querySelectorAll('div#form input'));
- allInputs.pop();
- const allLabels = Array.from(document.querySelectorAll('div#form label'));
- const submitBtn = document.querySelector('#submitBTN');
- const ul = document.querySelector('#infoPreview');
- const editBtn = document.querySelector('#editBTN');
- const continueBtn = document.querySelector('#continueBTN');
- const mainDiv = document.querySelector('#block');
- submitBtn.addEventListener('click', function (e) {
- e.preventDefault();
- const inputValues = allInputs.map((x) => x.value);
- if (inputValues[0] == '' || inputValues[1] == '') {
- return;
- }
- submitBtn.disabled = true;
- for (let i = 0; i < allInputs.length; i++) {
- let li = document.createElement('li');
- li.textContent = allLabels[i].textContent + ' ' + inputValues[i];
- ul.appendChild(li);
- }
- editBtn.disabled = false;
- continueBtn.disabled = false;
- allInputs.forEach((inp) => (inp.value = ''));
- editBtn.addEventListener('click', function (e) {
- for (let i = 0; i < allInputs.length; i++) {
- allInputs[i].value = inputValues[i];
- }
- submitBtn.disabled = false;
- editBtn.disabled = true;
- continueBtn.disabled = true;
- ul.innerHTML = '';
- });
- continueBtn.addEventListener('click', function (e) {
- mainDiv.innerHTML = '<h3>Thank you for your reservation!</h3>';
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement