How can I get some input from user using javascript?
or
How to use prompt method for getting data in javascript?
Explanation
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.
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.
<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.
A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script.
Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.