Dialog box in ES6

Dialog box in ES6

A dialog box can be defined as a regular type of window in the Graphical User Interface (GUI) of the operating system. It is also spelled as a dialogue box. It is prompt to provide the select commands and information.

There are three types of dialog boxes used in ES6 such as-

  • Prompt Dialog Box
  • Confirmation Dialog Box
  • Alert Dialog Box

 The dialog boxes are used to perform the following specific tasks-

  • To take input from the user  
  • To raise an alert message
  • To take confirmation on input and event

Here, we will try to elaborate each type of dialog box in detail.

Prompt Dialog Box

The prompt dialog box is used when we need to pop-up a text box to take input from user side. It enables us to interact with the user. The prompt dialog box contains two buttons- Ok and Cancel.

If the user requires providing input to the textbox, click Ok. When the user clicks on the Ok button, then the dialog box interprets the value and returns it to the user. If the user click on the Cancel button, the prompt method () return the null value.

Syntax

prompt(message, default_string);   

Example

Here, we have an example to understand the prompt dialog box.

<html>  
<head>   
    <script type="text/javascript">  
        function display() {  
            var value = prompt("Enter the Name : ", "Enter the name");  
            document.write("The Name is : " + value);  
        }  
    </script>  
</head>  
<body>  
    <center>  
        <h1>Hello ES6</h1>  
        <h2>Welcome to ES6</h2>  
        <p>Click on the button </p>  
        <input type="button" value="Click Me" onclick="display();" />  
    </center>  
</body>  
</html>

Output

After the execution of the code, we got the following output:

Dialog box in ES6

After the clicking on the button, we got the following output:

Dialog box in ES6

When we entered the name and click, OK, we got the following output:.

Dialog box in ES6

As shown in the snippet above, we entered Robert after the click on OK button we got the following output.

Dialog box in ES6

Confirmation Dialog Box

The confirmation dialog box is used, when we require taking the consent on any option from the user side. The confirmation dialog box also contains two buttons- Ok and Cancel.

It has a confirm method (). If the user clicks on the Ok button, the confirm method () returns true. But if the user clicks on the cancel button, the method returns false. For Example- If a user wants to delete some data, the page can confirm it with the help of a confirmation box.

Syntax

confirm(message);

Example

Here, we have an example to understand the above dialog box.

<html>  
<head>   
    <script type="text/javascript">  
        function display() {  
            var c = confirm ("Do you want to continue ?");  
            if(c == true) {  
                document.write ("We Want to continue");  
            }   
            else {  
                document.write ("We does not want to continue");  
            }  
        }  
    </script>  
</head>  
<body>  
    <center>  
        <h2>Hello ES6</h2>  
        <h3>Welcome to ES6</h3>  
        <p>Click on the button </p>  
        <input type="button" value="Click Me" onclick="display();" />  
    </center>  
</body>  
</html> 

Output

After the successful execution of the code, we got the following output:

Dialog box in ES6

When we click on the button, then we will get the following output.

Dialog box in ES6

Now, if we click on Ok, we got the following output:

Dialog box in ES6

If we click on the Cancel option, then we will get the following output.

Dialog box in ES6

Alert Dialog Box

The alert dialog box is used when the system needs to send a warning message to the user. It is a commonly used dialog box in ES6. The alert dialog box only contains OK button to select the next task and continue. For example, if an input area requires to be filled, but the user skips that input area, then the alert dialog box is used to show a warning message to the user.

Syntax

Alert(message);

Example

An example is given below to understand the alert dialog box.

<html>  
<head>  
    <script type="text/javascript">  
        function display() {  
            alert("Alert dialog box");  
        }  
    </script>  
</head>  
<body>  
    <center>  
        <h2>Hello User</h2>  
        <h3>Welcome ES6</h3>  
        <p>Click on the button </p>  
        <input type="button" value="Click Me" onclick="display();" />  
    </center>  
</body>  
</html>

Output

We will get the following output, after the successful execution of the code.

Dialog box in ES6

When we click on the button, we got the following output:

Dialog box in ES6

Related Topics

Dialog box in ES6

Dialog box in ES6 A dialog box can be defined as a regular type of window in the Graphical User Interface (GUI) of the operating system. It is also spelled as...

5 minutes read.

String in ES6

String in ES6 The term string can be defined as an object used to represent the sequence of the characters. The string is widely used to store a text-based value like...

9 minutes read.

Set in ES6

Set in ES6 A Set is a kind of object used to create a group of unique values. The values stored in a set can be string, literal, array, and integer....

6 minutes read.

Boolean in ES6

Boolean in ES6 In ES6, the Boolean object is used to show two values either it may be true or false. In JavaScript, we can use the Boolean object as a...

4 minutes read.

Decision-Making in ES6 | ECMAScript 6

Decision-Making in ECMAScript 6 The Decision-making structure or statements are used to determine one or more than one condition to be evaluated or tested. The Decision-making statement helps us to decide...

7 minutes read.

Spread Operator in ES6

Spread Operator in ECMAScript 6 The term 'Spread Operator' can be defined as an operator that allows expending the array into separate elements. Three dots (…) isthe syntax of the Spread Operator.The Spread operator...

5 minutes read.

Void Keyword in ES6

Void Keyword in ES6 In ES6, the void keyword is referred to as a function return type, but it does not return any value. It classifies the expression and returns the...

2 minutes read.

Events in ES6

Events in ES6 The events can be defined as the actions or the occurrence of an action that is perceived by the software. The event is used to handle the interaction between...

14 minutes read.

Class in ES6

Class in ES6: The Class is a basic term in object-oriented programming (OOPs). A class helps to determine the prototype for modeling in real-world objects. It is used to formulate...

4 minutes read.

ES6 Tutorial

Introduction of ES6 The ECMAScript 6 is a scripting language specification institutionalized by ECMA International. ECMA, named in 1994, is an international organization, related to information and communication system. ECMA stands for “European Computer Manufacturers...

8 minutes read.

Types of Inheritance in ES6

Types of Inheritance The term inheritance can be divided into following three parts- Single-level InheritanceMultiple InheritanceMulti-level Inheritance Single-level Inheritance The single-level inheritance can be defined as an inheritance in which the child class can...

5 minutes read.

Variables in ES6 | ECMAScript 6

Variables in ECMAScript 6 A Variable is a place in memory used to store a value. There are some rules for declaration of the variable- Variable Initialization Initialization is a process of locating and storing the initial...

4 minutes read.

Module in ES6

Module in ES6 In ES6, the modules can be defined as a small chunk of program code stored in a file. The modules are used to modularize the source code with...

6 minutes read.

Template Literals in ES6

Template Literals in ES6            ES6 introduced a new feature called template literals. It facilitates us to define a multiline string and executes the string interpolation. The template literals are referred to...

3 minutes read.

Array in ES6

Array in ES6 The array can be defined as an object that is used to display the set of homogenous type of elements in ECMAScript 6. The array provides the facility to store...

5 minutes read.

Features of ES6 | ECMAScript 6

The ES6 or ECMAScript 2015 came with various exiting and new features. These features make it a more robust and updated programming language than ES5. Some of these new promising features are Const...

6 minutes read.

Immediately Invoked Function Expression ES6

Immediately Invoked Function Expression (IIFE) Immediately Invoked Function Expression (IIFE) is a JavaScript function used to ignore the variable hoisting from inside the code block. An IIFE is a function that runs...

3 minutes read.

Operators in ES6 | ECMAScript 6

Operators in ECMAScript 6 The term Operator is refers to a symbol that is used to instruct the computer system to perform a specific operation. The ECMAScript 2015 supports a rich set of operators....

11 minutes read.

Object Destructuring in ES6

Object Destructuring in ES6 The term destructuring is referred to as the breakdown of the complex entities into simpler parts. It works like array destructuring. In the array destructuring, the values...

3 minutes read.

Page Redirect in ES6

Page Redirect in ES6 The term redirect can be defined as a process to send the user and search engine on a specified URL from the original page. “The page redirection is...

3 minutes read.