Window.prompt() (Method)

Present a text input prompt box.


JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
Property/method value type:String primitive
JavaScript syntax:-myResult = myWindow.prompt(aString, aDefaultValue)
-myResult = prompt(aString, aDefaultValue)
Argument list:aDefaultValueAn initial content for the text box
aStringSome text to explain what to enter

This presents a modal dialog containing the prompting text message, a text cell to type into and two buttons, OK and Cancel.

This method is useful for debugging where you need to enter values.

Note that the text that is presented in the dialog is unformatted text and you cannot use HTML in the dialog box.

The title bar of the dialog box cannot be changed from its default setting which tells you that the dialog was invoked by JavaScript. In some browsers, it may just display the name of the browser. This is intended to stop script programmers from masquerading their dialog boxes as those of operating system diagnostics and login screens.

The prompt() dialog box is modal and blocking. The script must wait for a response from the user.

The value returned by the method is the text typed into the box by the user before pressing the OK button to dismiss the dialog. If the Cancel button is clicked, the method will return null instead.


See also:Debugging - client-side, Dialog boxes, Dialog object, Frame object, Window object, Window.alert(), Window.confirm()

insert figure 0121


Wrox Instant JavaScript - page - 78