SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Getting user data by using prompt window in JavaScript

By using JavaScript prompt we can ask the visitor to enter data to our system for further processing. The prompt command will display a window and ask visitor to enter some data. We can collect the data entered by the user and store them in a variable. Here is some example.

var my_string = prompt("Please enter your name");
document.write(my_string)

We can show some default text while displaying the prompt. Here is an example where a default message is displayed for the visitor to enter first name.

var my_string = prompt("Please enter your name","enter your first name only");
document.write(my_string)

The above code will display the prompt window with some default text.

We can check the entered data by using if else condition.
Here is the demo of this code. Click the button below to display the prompt message.




Further readings
window.onload: for functions to execute as soon as page loads
Displaying alert window with message
prompt window for user input
Confirm window for user choice
Opening a child window
Closing child window on click of a button
Refreshing parent window from child window
Passing of data from child window to parent window
Showing a conformation window to user before deleting
Displaying JavaScript pop up window
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust