firstPHP/public/js/ajax.js

52 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-04-16 17:13:42 +03:00
function ajaxRequest() {
const request = new XMLHttpRequest();
2024-04-17 17:30:00 +03:00
request.open("GET", "/admin/form-add-fields");
2024-04-16 17:13:42 +03:00
request.addEventListener("load", () => {
const responseText = request.responseText;
const targetElement = document.getElementById("buttonAdd");
2024-04-16 17:54:37 +03:00
const divElement = document.createElement("div");
divElement.classList.add("form-control");
2024-05-03 18:11:43 +03:00
divElement.style.backgroundColor = "#bbbbbb";
2024-04-16 17:54:37 +03:00
divElement.innerHTML = responseText;
targetElement.insertAdjacentElement("beforebegin", divElement);
2024-04-16 17:13:42 +03:00
2024-05-03 18:11:43 +03:00
const deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.addEventListener("click", () => {
divElement.remove();
});
divElement.appendChild(deleteButton);
2024-04-16 17:13:42 +03:00
});
request.send();
2024-04-17 17:30:00 +03:00
}
2024-05-03 18:11:43 +03:00
2024-04-17 17:30:00 +03:00
function getValueSelect(){
var selectValue = document.getElementById("selectID").value
2024-04-22 11:31:44 +03:00
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)
2024-04-17 17:30:00 +03:00
request.addEventListener("load", () => {
var responseText = request.responseText;
var targetElement = document.getElementById("buttonAdd");
var divElement = document.createElement("div");
2024-05-03 18:11:43 +03:00
divElement.classList.add("form-control form-new-block");
2024-04-17 17:30:00 +03:00
divElement.innerHTML = responseText;
targetElement.insertAdjacentElement("beforebegin", divElement);
2024-05-03 18:11:43 +03:00
const deleteButton = document.createElement("button");
deleteButton.textContent = "X";
deleteButton.classList = 'btn-danger delete-button';
deleteButton.addEventListener("click", () => {
divElement.remove();
});
divElement.appendChild(deleteButton);
2024-04-17 17:30:00 +03:00
});
request.send()
}
2024-05-03 18:11:43 +03:00
function getIdBlock(){
}