skip to content
Just Change Direction

Javascript confirm()

/ 1 min read

Whilst checking out the RedwoodJS docs today, I came across a neat little trick for using the JavaScript confirm() function to create a simple confirmation dialog.

The confirm() function is a built-in JavaScript function that displays a dialog with an optional message and two buttons: OK and Cancel. If the user clicks OK, the function returns true. If the user clicks Cancel, the function returns false.

Here’s a simple example of how you might use confirm() to create a confirmation dialog:

function deleteItem() {
if (confirm("Are you sure you want to delete this item?")) {
// Code to delete the item
}
}

Docs are here: https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm