Window Prompt Method

How can I get some input from user using javascript?
How to use prompt method for getting data in javascript?


Object: Window
Method or Function: prompt(string)
Description: This method is used for getting dynamic user input or data. It takes the message as argument. User is prompted with input box to enter the data.


For an example we will prompt a message box asking for his name. Once the user enters the name we will get it and show it in the text field.

Example Code:
<form name=tett>
<input type=text name=tf value="testing prompt" size=15>
<script language=javascript>
var df = prompt(" enter your name "); = df;


In the above example,
  • first we created a form named tett.
  • form containing a text and button.
  • in the javascript code, we invoke a prompt box with a message.
  • we get the user input in the variable named df.
  • we set the name as value to the text field tf.

Ask Questions

Ask Question