JavaScript Confirm

The JavaScript confirm box gives your users a chance to confirm an action before JavaScript runs it. The 'confirm' box is created using JavaScript's built-in confirm() function. When the JavaScript confirm() function is triggered, a small box will pop up and display an "OK" button and a "Cancel" button (along with text that you specify in your JavaScript code).

Creating/Triggering a JavaScript Confirm

As mentioned, you create a JavaScript confirm box by calling the built-in JavaScript confirm() function. All you need to do is pass your message to this function.

Basic JavaScript Confirm

You can place the JavaScript confirm() function straight into an HTML tag. Like this:

JavaScript 'confirm()' Within Another Function

The above example works, but it doesn't really do much. You could make your website more useful by including the confirm() function within another function.

Here's an example: