- Alert Box
- Confirmation Box
- Prompt Box
All of these popups open a modal window, meaning that the user cannot interact with the rest of the components of the web page without responding to this window first. In this article, we will discuss between the most two confusing pop-up box Alert and Confirmation box.
- An alert box is used to inform/alert the user about an event.
- This type of popup box has only one button, named ‘OK’, and has no return value.
- Alert Box can be called using the function alert(“message”).
- A Confirmation Box is used to provide user with a choice about an event.
- This type of popup box has two buttons, named ‘OK’ and ‘Cancel’, and return ‘true’ and ‘false’ when respective buttons are clicked.
- Confirmation Box can be called using the function confirm(“message”).
Below example illustrates the differences between alert Box and confirmation Box. Example:
Action-based on Confirmation Box returns different values. But alert box return only agreed value that user have-
- 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.
- We achieve this by modifying the function ‘confirmationBox()’ in the above code snippet.
Output : Output in browser console when ‘OK’ and later ‘Cancel’ buttons are pressed.
Let us see the differences in a tabular form -:
|alert box||confirmation box|
|1.||Alert box is used if we want the information comes through to the user.||Confirm box is used if we want the user to verify or accept something.|
|2.||You need to click “OK” to proceed when an alert box pops up.||We need to click either “OK” or “Cancel” to proceed when a confirmation box pops up.|
Its syntax is -:
Its syntax is -:
|4.||It always return true we always need to click on “OK” to proceed further.||It return true if we click “OK”|
|5.||The alert box takes the focus away from the current window and forces the browser to read the message.||It returns false if we dont click on “OK”|