Updated on Kisan Patel
If we want to confirm an action from user, we need to use javascript confirm() method.
The javascript confirm()
method displays a confirm dialog box with a message with an OK and Cancel button.
The confirm method() returns true if the user clicked “OK”, otherwise return false.
<!-- HTML --> <input type="button" onclick="ConfirmMe()" value="Click me to confirm!" /> <!-- Javascript --> <script type="text/javascript"> function ConfirmMe() { var c = confirm('Are you sure to proceed?'); if (c) { // OK pressed; user confirmed to proceed further alert("You pressed OK!"); } else { // Cancel pressed; user do not want to proceed alert("You pressed Cancel!"); } } </script>
See the Pen zGXwdr by Kisan (@pka246) on CodePen.