- 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");
|1. Alert Box||Warn users||window.alert(“Too many windows open!“);|
|2. Confirmation Box||Ask for user confirmation before accessing the page||window.confirm(“Do you want to proceed?“);|
|3. Prompt Box||Ask for the user input||window.prompt(“Give your name“, “Unnamed“);|
1. Alert Box
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.
2. Confirmation Box
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?");
3. Prompt Box
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 for user input before continuing on the page
Thanks for reading.
About the Author
- I'm an entrepreneur and a blogger from Finland. My goal is to make coding and tech easier for you with comprehensive guides and reviews.
- Artificial Intelligence2023.05.16Humata AI Review (2023): Best PDF Analyzer (to Understand Files)
- Python2023.05.139 Tips to Use ChatGPT to Write Code (in 2023)
- Artificial Intelligence2023.04.1114 Best AI Website Builders of 2023 (Free & Paid Solutions)