Skip to main content

Create a Confirm Modal Box-HTML, CSS, Javascript


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

<style type="text/css">

.confirm-box{

background-color: rgba(0, 0, 0, 0.5);

width:100%;

height:100%;

position: fixed;

top:0;

left:0;

z-index: 9999;

display: flex;

justify-content: center;

align-items: center;

}


.message-box{

background-color:#fff;

text-align: center;

font-family:arial;

font-family:16px;

line-height: 1.5;

padding:20px;

border-radius:5px;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);

}

.button-box{

margin-top:30px;

}

.yes-button,.no-button{

                              padding:10px 20px;

                              font-size:20px;

                              margin:0 20px;

                              border: none;

                              border-radius: 5px;

                              cursor: pointer;



}


.yes-button{

background-color: green;

color: #fff;

}

.no-button{

background-color:red;

color:#fff;

}

</style>

<title>Alert</title>

</head>

<body>

<button id="openCofirmBox">Confirm Box</button>




<script type="text/javascript">

function showConfirm(message,callback){

var confirmBox = document.createElement("div");

confirmBox.classList.add('confirm-box');

var messageBox = document.createElement("div");

messageBox.classList.add('message-box');

messageBox.textContent = message;

confirmBox.appendChild(messageBox);


var buttonBox = document.createElement("div");

buttonBox.classList.add('button-box');

messageBox.appendChild(buttonBox);

var yesButton = document.createElement("button");

yesButton.classList.add('yes-button');

yesButton.textContent = "yes";

yesButton.addEventListener('click',YesButtonClick);

buttonBox.appendChild(yesButton);

var noButton = document.createElement("button");

noButton.classList.add('no-button');

noButton.textContent = "No";

noButton.addEventListener('click',NoButtonClick);

buttonBox.appendChild(noButton);


function removeConfirmBox(){

document.body.removeChild(confirmBox);

}

function YesButtonClick(){

callback(true);

removeConfirmBox();


}



function NoButtonClick(){

callback(false);

removeConfirmBox();


}

document.body.appendChild(confirmBox);






}



document.querySelector("#openCofirmBox").addEventListener('click',()=>{

showConfirm("Are you sure to delete the data?",function(result){

if(result){

console.log("you pressed yes.");


}else{

console.log("you pressed no.");


}


});



});


</script>



</body>

</html>


Download Source Code:

https://github.com/dastgir999/HTML-CSS-JS-Confirm-Modal.git

Comments

Popular posts from this blog

Creating a Student Marksheet using Microsoft Excel.

 Creating a Student Marksheet using Microsoft Excel.  Creating a student marks sheet in MS Excel is straightforward. Here's a step-by-step guide to design one: Step 1: Open MS Excel Launch MS Excel and open a new workbook. Step 2: Structure the Sheet Header Section: Use the first few rows to include the title, such as "Student Marks Sheet" and relevant details like the class, semester, or term. Column Headings: In Row 5 (or below the title), define your column headers: Column A: Roll Number Column B: Student Name Column C onward: Subjects (e.g., Mathematics, Science, English, etc.) Final Columns: Include Total Marks , Percentage , and Grade . Example: Roll No.Student Name Mathematics Science English Total Marks Percentage Grade Step 3: Input Data Enter the roll numbers, student names, and their marks under respective columns. Step 4: Add Formulas Total Marks: In the "Total Marks" column, use the formula to sum marks: =SUM(C2:E2) Copy this ...

Backup one folder to another location

 You can create a simple batch file (.bat) to back up a folder automatically in Windows. Here’s a step-by-step example: 🔹 Example: Backup one folder to another location @echo off set source="C:\MyData" set destination="D:\Backup\MyData_%date:~-4%-%date:~7,2%-%date:~4,2%" echo Backing up from %source% to %destination% xcopy %source% %destination% /E /H /C /I /Y echo Backup completed! pause 🔹 Explanation: set source= → Source folder you want to back up. set destination= → Destination folder where backup will be stored. %date:~-4%-%date:~7,2%-%date:~4,2% adds today’s date in YYYY-MM-DD format to the folder name (so each backup is stored separately). xcopy options: /E → Copy all subdirectories (including empty ones). /H → Copy hidden + system files. /C → Continue even if errors occur. /I → Assume destination is a folder. /Y → Suppress overwrite prompts. 🔹 Usage: Open Notepad . Paste the code above. Save it...

How to create a simple Shopping App with PHP AJAX MYSQL?

  Below is the complete code for the PHP, MySQL, and AJAX-based shopping cart application with features like adding products to the cart, updating cart quantities, and checkout with Cash on Delivery (COD). This includes all the necessary files and steps to set up the application. --- 1. Database Setup Run the following SQL queries to create the database and tables: ```sql CREATE DATABASE shopping_cart; USE shopping_cart; -- Products table CREATE TABLE products (     id INT AUTO_INCREMENT PRIMARY KEY,     name VARCHAR(255) NOT NULL,     price DECIMAL(10, 2) NOT NULL,     description TEXT,     image VARCHAR(255) ); -- Orders table CREATE TABLE orders (     id INT AUTO_INCREMENT PRIMARY KEY,     customer_name VARCHAR(255) NOT NULL,     customer_email VARCHAR(255) NOT NULL,     customer_address TEXT NOT NULL,     total_amount DECIMAL(10, 2) NOT NULL,     status ENUM('pending', ...