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.

Syntax

[window].alert(“Text to be displayed on the popup box”);

The word window is optional.

Example

window.alert(“I am to alert you about ….”);
or
alert(“I am to alert you about ….”);

Output

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.

Syntax

[window].confirm(“Text to be confirmed”);

Example

confirm(“Do you want to quit now?”);

Output

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.

Syntax

prompt(“Message” [, “default value in the text field”]);

Example

var name = prompt(“What’s your name? “, “Your name please…”);

Output

A prompt box returns input string value when the user clicks “OK”. If the user clicks “Cancel”, it returns null value.



Programs

java script code to show the reservation system of XYZ

View Solution


java Script Application for Student attendance

View Solution


java script function max to find largest number

View Solution


JavaScript code that calculates the squares and cubes from 0 to 10

View Solution


JavaScript code to design a simple calculator to perform the following operations sum product difference and quotient

View Solution


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