www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript Prompt Box Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49
There may be times when we need to get input from the user in our code e.g. sometimes we may need the name of the user.

In this lesson we will discuss how we can get uner input in a JavaScript program.

We can get user input in a JavaScript program through a prompt box.

A prompt box, when popped up, contains two buttons "OK" and "Cancel", along with an input field for the user to enter input.

The basic syntax for popping up a prompt box follows:

prompt("Message Text ", "defaultvalue");

The above line of code opens / pops up a dialog box having an input field with the "defaultvalue" already entered and two buttons i.e. "OK" and "Cancel". If the user clicks the "OK" button the prompt() returns the value entered in the input field. Otherwise the prompt() returns null.

The following example pops up a prompt box asking user to enter his / her name. After the user clicks on the "OK" button the value in the input filed is displayed in an alert box:

<script type="text/JavaScript">

var name = prompt("Enter Your name", "Hello World");
alert(name);

</script>


Next >>> Lesson No. 24: JavaScript Events





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.