window.prompt()

JavaScript1.0+, JScript1.0 Nav2+, IE3+, Opera3+ Syntax

							window.prompt(string1, string2)

Description

The prompt() method of the Window object displays a prompt dialog box when invoked. The value of string1 passed to the method is displayed in the box, and the value of string2 is contained in the text field of the prompt dialog box. The returned value of this method is the text in the text field.

Example

Listing 7.573 pops up a prompt box when the script is loaded asking the user for a password. If the correct password is entered, the page finishes loading. The result of running this script can be seen in Figure 7.20.

Figure 7.20. An alert box created with the Window.prompt() method.

Listing 7.573 A Prompt Box ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.