Window Prompt Method
How can I get some input from user using javascript?
or
How to use prompt method for getting data in javascript?
Explanation
Object:
WindowMethod 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.
Example:
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>
</form>
<script language=javascript>
var df = prompt(" enter your name ");
document.tett.tf.value = df;
</script>
Result:
Explanation:
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.