ÄúµÄλÖãºÑ°ÃÎÍøÊ×Ò³£¾±à³ÌÀÖÔ°£¾JavaScript£¾Javascript Tutorial
Javascript Tutorial

Javascript - Intro
Javascript - Syntax
Javascript - Location
Javascript - External
Javascript - Operators
Javascript - Variables
Javascript - Functions
Javascript - Events
Javascript - Statements
Javascript - If
Javascript - Else If
Javascript - While
Javascript - For Loop
Javascript - Comments
Javascript - Array
Javascript - Alert
Javascript - Confirm
Javascript - Prompt
Javascript - Print
Javascript - Redirect
Javascript - Pop Up
Javascript - Date
Javascript - Form
Javascript - Void 0

Javascript String

Javascript - Strings
Javascript - Length
Javascript - Split
Javascript - Search
Javascript - Replace
Javascript - indexOf
Javascript - Compare

Javascript Advanced

Javascript - getElementById
Javascript - innerHTML

Javascript Prompt

The Javascript prompt is a relic from the 1990's that you seldom see being used in modern day websites. The point of the Javascript prompt is to gather information from the user so that it can be used throughout the site to "personalize" it for the visitor.

Back in the day you'd often see these prompts on personal web pages asking for your name. After you typed in the information you would be greeted with a page that had a welcome message, such as "Welcome to My Personal Web Page John Schmieger!" (If you name just happened to be John Schmieger).

The Javascript prompt is not very useful and many find it slightly annoying, but hey, this tutorial is here to educate you, so let's learn how to make that prompt!

Simple Javascript Prompt

You can use a prompt for a wide variety of useless tasks, but below we use it for an exceptionally silly task. Our prompt is used to gather the user's name to be displayed in our alert dialogue box.

HTML & Javascript Code:

<head>
<script type="text/javascript">
<!--
function prompter() {
var reply = prompt("Hey there, good looking stranger!  What's your name?", "")
alert (reply)
}
//-->
</script>
</head>
<body>
<input type="button" onclick="prompter()" value="Say my name!">
</body>

Display:

Recap on Javascript Prompt

It sure is a quick way to gather some information, but it is not as a reliable information gatherer as the other options available to you. If you want to find out someone's name and information, the best way to request this information would be to use HTML Forms. And if you wanted to use the information throughout the website, you might use some PHP to get that job done in a more sophisticated manner.