Prompt Dialog Box in JavaScript

 
Suppose you want to require user interaction on the webpage for example if you want to display a dialog box that has some predefined message, a textbox that accepts user input and Ok and cancel button then we can use prompt dialog box in JavaScript.we know that Alert dialog box simply dislays information in a browser and does not allow any user interaction.
In prompt dialog box if user click on ‘Ok’ button then text types inside the textbox will be pass to the program environment otherwise if user click on ‘Cancel‘ button then it return null to the environment.

Prompt() method requires two blocks of information:
A message to be displayed as a prompt to the user
Any message to be displayed in the textbox, this is optional.
we can use Prompt() in JavaScript as:

prompt(“message“,”default value“)

Example:

<html>
  <head>
    <title>example</title>
  </head>
  <body>
    <script language="javascript">
       document.write("<H1>Welcome,");
       document.write(prompt("Please enter your name :"," Name"));
    </script>
  </body>
</html>