Javascript alert, confirm, and prompt boxes
Javascript provides a few popup boxes to interact with the user. More specifically, alert, confirmation, and prompt boxes.
This tutorial focuses on:
- Displaying an alert box
- Displaying a confirmation box
- Displaying a prompt box
Displaying an alert box
An alert box can be displayed using Javascript's alert() function.
Displaying a confirmation box
A confirmation box is used to let the user make a choice. A confirmation box will appear will with an "OK" button and a "Cancel" button. Different actions will occur depending on what button the user clicks. You can specify this course of action with conditional logic.
A confirmation box can be displayed using Javascript's confirm() function.
Displaying a prompt box
A prompt box is used to get data from the user. A prompt box will appear with an "OK" button and a "Cancel" button. Different actions will occur depending on what button the user clicks. If the user clicks the "OK" button, the value entered into the prompt box will be set. If the user clicks the "Cancel" button, a null value (empty string) will be set, or a default value if you set it as the second argument in the function.
A prompt box can be displayed using Javascript's prompt() function.