- Alert Box.
- Confirm Box.
- Prompt Box.
Here is the syntax for using each of them:
// Alert window.alert("something"); // Confirm window.confirm("something"); // Prompt window.prompt("something", "default text");
In this guide, you learn what these popups do and how to use them.
You can create an alert box with the built-in alert() method. This method takes one argument which is the alert message to be displayed.
The confirmation popup box is used to display a dialog with a message and two buttons, “OK” and “Cancel”.
To create a confirmation box, use the built-in confirm() method. This method takes one argument which specifies the confirmation message to be displayed.
The confirmation box (the confirm() method) returns true if the user clicks “OK”, and false on “Cancel”.
The idea behind the confirmation box is to prevent access to the page before clicking and closing the box.
confirm("Do you want to continue?");
The prompt box displays a modal with a message that asks a user to enter text input.
- The text to be displayed.
- The optional default text to the input field.
The prompt box (the prompt() method) returns the text entered by the user as a string. If no text was entered, a null is returned.
Here is an example use:
prompt("Enter a name you want to be called on the site: ", "Charlie");
- Use an alert box by calling the alert() method to display a warning/message.
- Use a confirmation box by calling the confirm() method to display a confirmation message.
- Use a prompt box by calling the prompt() method to ask user input before continuing on the page
Thanks for reading.