JS Popup Boxes
Alert( ) method of window object creates a small dialog box with a short text message and “OK” command button called alert box. Alert box contains an icon indicating a warning.
[window].alert(“Text to be displayed on the popup box”);
The word window is optional.
window.alert(“I am to alert you about ….”);
alert(“I am to alert you about ….”);
An alert box is used if we want to display some information to the user. When an alert box appears, the user needs to click “OK” button to proceed.
Confirm box is used if we want the user to verify and confirm the information. The user will have to click either “OK” or “Cancel” buttons.
[window].confirm(“Text to be confirmed”);
confirm(“Do you want to quit now?”);
Confirm box returns a Boolean value. If the user clicks on “OK”, it returns true. If the user clicks on “Cancel”, it returns false.
Prompt box allows getting input from the user. We can specify the default text for the text field. The information submitted by the user from prompt( ) can be stored in a variable.
prompt(“Message” [, “default value in the text field”]);
var name = prompt(“What’s your name? “, “Your name please…”);
A prompt box returns input string value when the user clicks “OK”. If the user clicks “Cancel”, it returns null value.