JS Popup Boxes

Javascript popup boxes (dialog boxes)

In JavaScript, three kinds of popup boxes – Alert box, Confirm box, and Prompt box can be created using three methods of window object.

Alert Box

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

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

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.


CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad