HTML and CSS Reference
Figure 4.2 After the first alert box appears and the user clicks OK, the second box appears.
A prompt() method asks the user for some small amount of information such as a pass-
word, completion of a form input, or personal information, such as nickname or title.
prompt dialog box and HTML forms are used (forms are discussed in Chapter 11,
“Working with Forms and Input Devices”). The prompt dialog box pops up with a sim-
ple textfield box. After the user enters text into the prompt dialog box, its value is
returned. This method takes two arguments: a string of text that is normally displayed
as a question to the user, prompting the user to do something, and another string of text
that is the initial default setting for the box. If this argument is an empty string, nothing
is displayed in the box. The prompt() method always returns a value. If the user clicks
the OK button, all the text in the box is returned; otherwise null is returned.
prompt("What is your name? ", "");
prompt("Where is your name? ", name);