JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




Window Prompt Method


Tutorials Javascript

Topic

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.


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.





  • 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.

    Other Links

    web hosting