• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Handling Data with Variables > Using the prompt() Method to Assign a...

Using the prompt() Method to Assign a Value to a Variable

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.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint