JavaScript confirm box is similar to alert message box that we learnt in JavaScript Alert Example article. In JavaScript, Confirm box is used to confirm the event action performed by the user interacting with the web page form inputs. E.g.: A user is trying to delete any item from his account then you can trigger a confirm box for that event to ask the user whether he is sure to delete that item or action. Confirm box displays 2 action buttons when it pops up at any event, it shows OK and CANCEL button. You can detect the button pressed by the user and can perform the required action when OK button is clicked by the user. 

Syntax of JavaScript Confirm Box

confirm([message]);

Example of confirm box in JavaScript

function confirmMessage() {
    var res = confirm('Are you sure?');

    if (res == true) {
        document.write('You clicked the OK button');
    }
    else {
        document.write('You clicked the CANCEL button');
    }
}

Above example shows that confirm box result is stored into variable res, then it is detected which button is being clicked by the user.

Continueto next tutorial: Javascript Prompt Box to learn how to open the prompt box using JavaScript prompt method.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.