• These popup boxes are mainly used for the purpose of Input and Output jobs in JS.
  • These are created using three methods of window object.


  • In JavaScript, there are three kinds of popup/dialog boxes – Alert box, Confirm box, and Prompt box. 

(A) Prompt Box :

    • Prompt() method is used to take singel input at a time from the user at run time. 
    • The information submitted by the user from prompt( ) can be stored in a variable.
    • A prompt box accept and then returns input string value to the variable when the user clicks OK button of the box. If the user clicks “Cancel”, it returns null value to the variable.
    • Syntax :
      var variablename=prompt(“Message of body of prompt box” [, “Message of the prompt text field box”]);
    • Example :
      var x= prompt(“Prompt box to enter the value “, “Enter the value here”);

(B) 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 displays the user’s output/message with ok confirmation button.
    • Alert box contains an icon indicating a warning.
    • Syntax :

[window].alert(“User Text/message to be displayed on the popup box”);
(Here, the word window is optional.)

    • Example :
var x=10;
alert(“Hello India”);

(C) Confirm Box :

    • Confirm box is used to confirm to continue the operation or stop it. For this, the user will have to click either “OK” or “Cancel” buttons.
    • Confirm box returns a Boolean value true/false. If the user clicks on “OK”, it returns true boolean value. If the user clicks on “Cancel”, it returns false boolean value.
    • Syntax :

[window].confirm(“User confirmation Text/message”);

    • Example :
confirm(“Do you want to delete the record permanently?”);
confirm(“Do you want to modify the record?”);



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.