You’re probably looking for confirm(), which displays a prompt and returns true or false based on what the user decided:

if (confirm('Are you sure you want to save this thing into the database?')) {
  // Save it!
  console.log('Thing was saved to the database.');
} else {
  // Do nothing!
  console.log('Thing was not saved to the database.');
}

Answer from s4y on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › met_win_confirm.asp
Window confirm() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › confirm
Window: confirm() method - Web APIs | MDN
window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Interaction: alert, prompt, confirm
... The second parameter is optional, but if we don’t supply it, Internet Explorer will insert the text "undefined" into the prompt. ... The function confirm shows a modal window with a question and two buttons: OK and Cancel.
🌐
Github
craftpip.github.io › jquery-confirm
jquery-confirm.js | The multipurpose alert & confirm
<a class="twitter" data-title="Goto twitter?" href="http://twitter.com/craftpip">Goto twitter</a> Javascript · $('a.twitter').confirm({ content: "...", }); $('a.twitter').confirm({ buttons: { hey: function(){ location.href = this.$target.attr('href'); } } }); The shorthand thingy takes in two string arguments, first one is the content of the dialog and second the title of the dialog. The second argument is optional. $.alert('Content here', 'Title here'); try me $.confirm('A message', 'Title is optional'); try me $.dialog('Just to let you know'); try me ·
🌐
PHPpot
phppot.com › javascript › javascript-confirm
JavaScript Confirm Dialog Box with Yes No Alert - PHPpot
This example connects the on-click event and the JS handler created for showing the confirm box. This JS code contains the HTML to display two buttons “Edit” and “Delete”. Each has the onClick attribute to call the JavaScript custom handler doAction().
🌐
W3Resource
w3resource.com › javascript › alert-prompt-confirm.php
JavaScript alert - prompt - confirm - w3resource
<!DOCTYPE html> <html lang="en"> <head> <meta charset=utf-8> <title>JavaScript confirm box example </title> </head> <body> <h1 style="color: red">JavaScript confirm() box example</h1> <hr /> <script type="text/javascript"> mess1='Press Ok to Continue.'; math=99; x = confirm(mess1); if (x == true) { alert("You have clicked on Ok Button."); } else { alert("You have clicked on Cancel Button."); } </script> </body> </html>
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › display-popup-message-in-javascript
JavaScript Message Boxes: alert(), confirm(), prompt()
alert("This is an alert message ... number alert(Date()); // display current date ... Use the confirm() function to take the user's confirmation before starting some task....
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-confirm-method
Javascript Window confirm() Method - GeeksforGeeks
July 12, 2025 - In this example The window.confirm() method displays a confirmation dialog when a user clicks the link. Returning true allows navigation; false cancels it, preventing the link from opening based on the user's choice.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-alert-box-and-confirmation-box-in-javascript
Difference between alert box and confirmation box in JavaScript - GeeksforGeeks
June 26, 2024 - <!DOCTYPE html> <html> <head> ... } </script> </body> </html> ... The confirm function displays a message and waits for the user to click "OK" or "Cancel"....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › alert
Window: alert() method - Web APIs | MDN
Alternatively <dialog> element can be used to display alerts. <dialog> element · confirm · prompt · Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Oct 4, 2023 by MDN contributors.
🌐
DEV Community
dev.to › codenextgen › interaction-in-javascript-alert-prompt-and-confirm-e80
Interaction in JavaScript: `alert`, `prompt`, and `confirm` - DEV Community
September 18, 2024 - The confirm method is used to display a dialog box with a message and two buttons: "OK" and "Cancel".
🌐
Josef Zacek
josefzacek.cz › home › what’s the difference between alert, confirm and prompt?
What's the difference between alert, confirm and prompt? - Josef Zacek
August 22, 2023 - <script> alert("This is an alert message."); </script> ... The confirm function displays a dialog box with a message and two buttons: “OK” and “Cancel.”
🌐
Educative
educative.io › answers › how-to-use-alert-prompt-and-confirm-in-javascript
How to use alert(), prompt(), and confirm() in JavaScript
let YOB = prompt('What is your Year of Birth?', 1900); const currentYear = new Date().getFullYear(); if(YOB === null) { YOB = 1900 } alert(`You are ${currentYear - YOB} years old!`); // You are 100 years old! The confirm method will display a confirm box that
🌐
TutorialsPoint
tutorialspoint.com › how-to-use-javascript-to-show-a-confirm-message
How to use JavaScript to show a confirm message?
In this tutorial, we will learn how to use JavaScript to show a confirm message. We use window.confirm() method of JavaScript to show a confirm message. A confirm message is enclosed in a confirm dialog box which is a modal window. Such a window take
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript bom › javascript confirm
JavaScript confirm
December 17, 2023 - let result = confirm('Are you sure you want to delete?'); let message = result ? 'You clicked the OK button' : 'You clicked the Cancel button'; alert(message);Code language: JavaScript (javascript)
🌐
Scaler
scaler.com › home › topics › javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
January 2, 2024 - Within the function, the confirm in javascript method prompts the user to confirm file deletion. The user's choice is stored in the userChoice variable. Clicking OK triggers an alert stating File deleted!.
🌐
Medium
medium.com › @stheodorejohn › exploring-alert-box-confirm-box-and-prompt-box-in-javascript-7d81429f825
Exploring Alert Box, Confirm Box, and Prompt Box in JavaScript | by Theodore John.S | Medium
July 22, 2023 - In web development, user interaction is a critical aspect of creating engaging and interactive applications. JavaScript provides built-in functions to display various dialog boxes that allow developers to communicate with users effectively. In this article, we will explore three commonly used dialog boxes: Alert Box, Confirm Box, and Prompt Box.