function ajaxRequest() { const request = new XMLHttpRequest(); request.open("GET", "/admin/form-add-fields"); request.addEventListener("load", () => { const responseText = request.responseText; const targetElement = document.getElementById("buttonAdd"); const divElement = document.createElement("div"); divElement.classList.add("form-control"); divElement.style.backgroundColor = "#bbbbbb"; divElement.innerHTML = responseText; targetElement.insertAdjacentElement("beforebegin", divElement); const deleteButton = document.createElement("button"); deleteButton.textContent = "Delete"; deleteButton.addEventListener("click", () => { divElement.remove(); }); divElement.appendChild(deleteButton); }); request.send(); } function getValueSelect(){ var selectValue = document.getElementById("selectID").value var request = new XMLHttpRequest(); let button = document.getElementById("buttonAdd"); let count = parseInt(button.dataset.count) + 1; button.dataset.count = count; console.log(count); request.open("GET", "/admin/set-value-select?value=" + selectValue + "&count=" + count, true) request.addEventListener("load", () => { var responseText = request.responseText; var targetElement = document.getElementById("buttonAdd"); var divElement = document.createElement("div"); divElement.classList.add("form-control form-new-block"); divElement.innerHTML = responseText; targetElement.insertAdjacentElement("beforebegin", divElement); const deleteButton = document.createElement("button"); deleteButton.textContent = "X"; deleteButton.classList = 'btn-danger delete-button'; deleteButton.addEventListener("click", () => { divElement.remove(); }); divElement.appendChild(deleteButton); }); request.send() } function getIdBlock(){ }