Bootstrap Confirm Delete Modal | Popup
Bootstrap Confirm Delete Modal | Popup:The Bootstrap Confirm Delete Modal is a pop-up window that appears when a user attempts to delete an item or perform a critical action. It serves as a confirmation prompt, ensuring that the user intends to proceed with the action. The modal typically includes a message informing the user about the consequence of their action and presents buttons to either confirm or cancel the operation. This prevents accidental or unintended deletions and allows users to make informed decisions before proceeding. The Bootstrap framework provides ready-made components and styles to easily implement this feature, enhancing the user experience and preventing data loss.




Thanks for your feedback!
Your contributions will help us to improve service.
What is the code snippet to create a Bootstrap confirm delete modal or popup?
The code provided demonstrates the usage of Bootstrap to create a confirmation modal for deleting an item. When the "Delete Item id 10" button is clicked, it triggers the display of the modal with the ID "deleteModal". The modal consists of a header, body, and footer. The header contains a title, and a close button.
The body displays a confirmation message asking if the user wants to delete the item. The footer includes a "Cancel" button to dismiss the modal and a "Delete" button for confirming the deletion. Additionally, there is a toast message displayed at the bottom-right corner, which serves as a notification.
Bootstrap Confirm Delete Modal | Popup - Example
xxxxxxxxxx
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal"
onclick="confirmDeleteModal('10')">Delete Item id 10</button>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Confirm Deletion</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to delete this item?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="confirmDelete">Delete</button>
</div>
</div>
</div>
</div>
<!-- Toast Message -->
<div class="toast align-items-center position-fixed bottom-0 end-0" role="alert" aria-live="assertive"
aria-atomic="true" style="width: 300px;">
<div class="toast-header">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted" id="toastTime"></small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
How can I create a Bootstrap Confirm Delete Modal or Popup using jQuery?
The code snippet represents a JavaScript function called confirmDeleteModal
, which is used to display a confirmation modal or popup for deleting an item. The function takes an itemId
parameter that specifies the ID of the item to be deleted.
Inside the function, the item ID is set as the text in the modal body by selecting the appropriate element using its ID.
The delete button's click event handler is set using jQuery. When the delete button is clicked, the function performs the deletion logic, logs a message indicating the deletion of the item ID, and hides the modal.
After that, a toast message is displayed using Bootstrap's toast component. The toast message indicates the successful deletion of item 10 and displays the current time obtained from the getCurrentTime()
function.
In summary, the confirmDeleteModal
function sets up a Bootstrap modal for confirming the deletion of an item and handles the deletion logic, hiding the modal, and displaying a toast message.
Bootstrap Confirm Delete Modal | Popup - Jquery Part
xxxxxxxxxx
function getCurrentTime() {
const now = new Date();
const timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
return timeString;
}
function confirmDeleteModal(itemId) {
// Set the item ID in the modal body
$("#deleteModal .modal-body").text("Are you sure you want to delete item ID: " + itemId + "?");
// Set the delete button's click event handler
$("#confirmDelete").off("click").on("click", function () {
// Perform the deletion logic here
console.log("Deleting item ID: " + itemId);
// Close the modal
var deleteModal = bootstrap.Modal.getInstance(document.getElementById("deleteModal"));
deleteModal.hide();
// Show the toast message
var toast = $(".toast");
toast.find('.toast-body').text('Item 10 Deleted Successfully');
$("#toastTime").text(getCurrentTime());
toast.toast("show");
});
}