Loading, please wait...

Confirm Dialog Box

Confirmation Dialog Box

 

Confirmation Dialog Box displays the dialog message with two buttons, “OK” and “Cancel”. This dialog box is used to get a value from the user by pressing one of the two keys which helps in executing the process or nullify that.

 

Mainly, it is used in order to get the confirmation from the user. Here, we use an inbuilt function confirm().

 

These two buttons mainly define two values, if the user pressed OK button means the value is true and if the user pressed Cancel button the value is false.

 

 

Code:

<html>
<body>
<h2>JavaScript Confirm Box</h2>

<script>
function Confirm() {
    var getconfirm =confirm("Hello TutorialsLink!");
    if (getconfirm==true) {
    document.write("User pressed OK!");
    } else {
        document.write("User pressed Cancel!");
    }
    }
</script>
<input type="button" value="Click Me!" onclick="Confirm();" />
</body>
</html>

 

 Here, as per the code is written it describes the confirmation dialog box in a way that when the user clicks the button then a dialog box appears with a confirmation message and the two buttons “OK” and “Cancel”.

 

Both buttons have their own functionality according to the code. If the user agrees with that message then it clicks the “OK” button otherwise the “Cancel” one.

 

 

Output: