Prompt Box In java Script

Prompt box is a dialog box which displays a message in a small window with a text box along with two buttons . One OK and other Cancel. Prompt method has ability to return the text kept with the prompt method’s text box , this value can be assigned to some variable and can be used as and when require.
 
Example
<html>

<head>

</head>

<body>

<script type=”text/JavaScript”>

prompt (“Enter your name”, “”)

</script >

</body>

</html>

 
 
Understanding the program:
A dialog box with a text box and two buttons will appear, the message typed with prompt method will be displayed on the dialog box the text box will appear blank , if any text is typed at the place of blank (“ ”), that text will appear in the text box on dialog box.
Click here to view result of this program on browser
 
Example
<html>

<head>

</head>

<body>

<script type=”text/javascript”>

prompt (“Enter your name”, ” enter your name here”)

</script >

</body>

</html>

 
Understanding the program :
A dialog box with a text box and two buttons will appear, the message typed with prompt method will be displayed on the dialog box the text box will appear filled with “ enter your name here “ text.
Click here to view result of this program on browser
 
Storing value accepted from a prompt box in variables :
<html>

<head>

</head>

<body>

<script type=”text/javascript”>

var name,address name=prompt (“Enter your name”, ” enter your name here”)

address = prompt (“Enter your address”, “Address Please “)

document.write(“Your Name : “+name);

document.write(“<br>Your Address : “+address);

</script >

</body>

</html>

 
Understanding program :
As we know that prompt method has the ability to return the text stored in it’s text box, so the name fed by the user will be stored in the name variable and address of user in address variable, which will be displayed on the screen by document.write method.
 
Output is :
Your Name : Rhythm
Your Address : A -45, Preet Vihar, Delhi – 110092
Scroll to Top