Confirmation Dialog Box
Confirmation Dialog Box It displays a dialog box with two buttons: OK and Cancel.
What will confirm Are you sure return if the user presses the Cancel button?
The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked “OK”, otherwise false .
What is the difference between confirm and alert method?
An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.
How do you use the Confirm box in react JS?
- Add an opaque full screen background to the DOM.
- Below that, add a div that acts as the confirm box container.
- Inside the div add a text and the Cancel and OK buttons.
The confirm() method is used to display a modal dialog with an optional message and two buttons, OK and Cancel. It returns true if the user clicks “OK”, and false otherwise. It prevents the user from accessing other parts of the page until the box is closed. message is the optional string to be displayed in the dialog.
Below example illustrates the differences between alert Box and confirmation Box. When ‘OK’ button is pressed in Confirmation Box, the function confirm() returns ‘true’, when ‘Cancel’ is pressed it returns ‘false’. Below is a simple If-Else statement to check the return type.