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); }); 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"); divElement.style.backgroundColor = "#bbbbbb"; // Задайте здесь свой нужный стиль divElement.innerHTML = responseText; targetElement.insertAdjacentElement("beforebegin", divElement); }); request.send() }