JavaScript Prompt box

Prompt boxes are usually use in situations when you want to take some information from a user. Suppose you want to know about the user who is opening your website or webpage. So for this you can use prompt boxes to take user name and you can store it in a JavaScript variable and use in your script. Example of prompt box is mentioned below: Code


<html>
  <head>
    <title>Prompt Box Example</title>
    <script type='text/JavaScript'>
      function prompt_box_example() {
        var emailIDVariable = prompt('Please enter your email ID', '');
        alert ('Your email id is : '+emailIDVariable);
      }
    </script>
  </head>
  
  <body>
    <a href='javascript:void(0);' onclick='prompt_box_example();'>
      Email ID Information
    </a>
  </body>
</html>
In above mention example we have written a function with the name of 'prompt_box_example()' and called it on onClick event of <a></a> tags . When you click on 'Email ID Information' link then a prompt dialog box will appear on the screen and ask for email id there when you will enter your email id then it will show an alert box which will show your email id.