Here is a function I've created to generate a confirmation box.
The issue I'm facing is that the function doesn't wait for the user to click before returning true/false based on the onclick events.
So, how can I solve this?
function Confirmation(title, message, confirm_button_value) {
if (
typeof title !== "undefined" ||
typeof message !== "undefined" ||
typeof confirm_button_value !== "undefined"
) {
if (title !== "" || message !== "" || confirm_button_value !== "") {
var confirmation;
var confirmation_box = document.createElement("div");
confirmation_box.classList.add("confirmation_box");
var title_container = document.createElement("div");
title_container.classList.add("confirmation_box_title");
title_container.innerHTML = title;
confirmation_box.append(title_container);
var message_container = document.createElement("div");
message_container.classList.add("confirmation_box_message");
message_container.innerHTML = message;
confirmation_box.append(message_container);
var buttons_container = document.createElement("div");
buttons_container.classList.add("confirmation_box_buttons");
var confirm_button = document.createElement("span");
confirm_button.classList.add("confirmation_box_confirm_button");
confirm_button.innerHTML = confirm_button_value;
buttons_container.append(confirm_button);
var cancel_button = document.createElement("span");
cancel_button.classList.add("confirmation_box_cancel_button");
cancel_button.innerHTML = "Cancel";
buttons_container.append(cancel_button);
confirmation_box.append(buttons_container);
document.body.append(confirmation_box);
confirm_button.onclick = function () {
confirmation = true;
};
cancel_button.onclick = function () {
confirmation = false;
};
return confirmation;
}
}
}
(I am interested in straightforward solutions.)