Popup Boxes

M2-R5.1 · Chapter 6: JavaScript and Angular JS · 2 min read

Popup Boxes 

Popup boxes are those windows that appear on screen during program execution.

Generally they come on screen either to take some input to user or to give some output to user or to give some kind of message to the user.

Java Script provided us three kind of popup boxes-

  1. Prompt box
  2. Alert box
  3. Confirm Box 

1.Prompt box

It creates a dialog box with the message specified by us and a single entry field with a default value.

User need to fill value in the field and click OK button. If user presses “Cancel” button in prompt dialog box then Null will be displayed in output. 
 Syntax –

<variable_name> = prompt (“message”, default value); 
Example  - var nm=prompt (“Enter your name:”); 

2.Alert box  

It is use to display a pop-up message to the user. This pop-up will have OK Button to close the popup. 
Syntax – alert(“message”+variable*); 
*Variables are optional. 
Example –

alert(“welcome to website “); 
                   alert(“Result”+r); 

Note - we Study about Confirm Box later.