January 2001
Beginner
312 pages
6h 4m
English
So far, you've seen examples of how to assign values to variables directly in the JavaScript. Sometimes, though, you can't do this. For example, if you ask the user a question, such as her name, you have no possible way to know what the answer might be (unless perhaps you have only one person visiting your site!).
Fortunately, assigning values to variables in mid-script is easy. The following example shows you how to use the prompt() method to accomplish this.
You once again begin with your blank HTML template page and into the <script> block add the prompt() method:
<html> <head> <title>A Simple Page</title> <script language="JavaScript"> <!-- Cloaking device on! prompt(); // Cloaking ...
Read now
Unlock full access