Availability: |
| ||||||
Property/method value type: | String primitive | ||||||
JavaScript syntax: | - | myResult = myWindow.prompt(aString, aDefaultValue) | |||||
- | myResult = prompt(aString, aDefaultValue) | ||||||
Argument list: | aDefaultValue | An initial content for the text box | |||||
aString | Some 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.
Earlier documentation refers to the presence of a Clear button but this is not in evidence when testing this function on MSIE and Netscape Navigator. The Clear button is unnecessary since the text is automatically selected and typing into the box clears any previous content. Pressing the Delete key will also clear the text.
Prev | Home | Next |
Window.print() | Up | Window.releaseEvents() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |