Window.prompt() MethodNameWindow.prompt() Method---get string input in a dialogAvailabilityNavigator 2.0, Internet Explorer 3.0 Synopsis
window.prompt(message) window.prompt(message, default) Arguments
ReturnsThe string entered by the user, or the empty string if the user did not enter a string, or null if the user clicked Cancel. DescriptionThe prompt() method displays the specified message in a dialog box that also contains a textual input field and OK, Clear, and Cancel buttons. Platform-dependent graphics in the dialog help to indicate to the user that her input is desired. The default argument specifies the text that initially appears in the input field. If default is null, or if this optional argument is not passed at all, then the initial text is "<undefined>". If default is the empty string ("") then the input field is initially empty. Otherwise, the input field displays the string or number that is passed as the default. If the user clicks the Cancel button, prompt() returns null. If the user clicks the Clear button, prompt() erases any current text in the input field. If the user clicks the OK button, prompt() returns the value current value displayed in the input field. Note, however, that if the input field is displaying "<undefined>" because the default argument was null or unspecified, then prompt() returns the empty string and not the string "<undefined>". Also note that prompt() always returns the user's input as a string value, even if default was specified as a numeric value. If necessary, you can use parseInt() or parseFloat() to convert the returned string to a number. The dialog box that is displayed by the prompt() method is modal--that is, it blocks all user input to the main browser window until the user dismisses the dialog by clicking on the OK or Cancel buttons. Since this method returns a value depending on the user's response to the dialog, JavaScript execution pauses in the call to prompt(), and subsequent statements are not executed until the user responds to the dialog. UsageNote that the question displayed in the dialog is a string of plain text, not of formatted HTML. Unlike the message displayed by the alert() and confirm() methods, the message displayed by prompt() may only be a single line long on Windows platforms. |
|