How to use Prompt Box in JavaScript

In this article I have described about prompt box used in JavaScript
  • 2492

JavaScript Popup Box

JavaScript provides the ability to pickup user input or small amount of text to user by using Popup box or Dialog Box.


JavaScript provides a prompt dialog box to customize any webpage output based on user input for user interaction.


prompt("<message>","<default value>");


prompt( "Enter Your Name : ", "Name");

Lets take an Example


<html xmlns="">



<button onclick="myFunction()">click</button>

<p id="val" /p>


<script type="text/javascript">

    function myFunction() {

        var a;


        var name = prompt("Please enter your name");


        if (name != null)


            a = "Hello " + name + "Welcome To MCN";

            document.getElementById("val").innerHTML = a;








when we enter name and click ok then output shows as

promt box.jpg

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.