Prompt Box

It is a type of pop up box which is used to get the user input for further use. After entering the required details user have to click ok to proceed next stage else by pressing the cancel button user returns the null value.

Syntax:  

prompt("your Prompt here");

Example: This example shows the implementation of the Prompt box.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        Pop-up Box type | Prompt Box
    </title>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
 
<body>
    <center>
        <h1>w3wiki</h1>
 
        <h3>Prompt Box</h3>
 
        <input type="button" onclick="geekPrompt();"
        value="Click here for Prompt box"/>
 
        <!-- Prompt box function -->
        <script>
            function geekPrompt() {
                let x = prompt("Enter your mail here : ");
                document.write("Your ID : " + x);
            }
        </script>
    </center>
</body>
</html>


Output: 

Output

What are the types of Popup box available in JavaScript ?

In Javascript, popup boxes are used to display the message or notification to the user.

There are three types of pop-up boxes in JavaScript:

Table of Content

  • Alert Box
  • Prompt Box
  • Confirm Box

Similar Reads

Alert Box

It is used when a warning message is needed to be produced. When the alert box is displayed to the user, the user needs to press ok and proceed....

Prompt Box

...

Confirm Box

It is a type of pop up box which is used to get the user input for further use. After entering the required details user have to click ok to proceed next stage else by pressing the cancel button user returns the null value....