Visit Mozilla.org

DOM:window.prompt

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Displays a dialog with a message prompting the user to input some text.

[edit] Syntax

result = window.prompt(text, value);
  • result is a string containing the text entered by the user, or the value null.
  • text is a string of text to display to the user.
  • value is a string containing the default value displayed in the text input field. It is an optional parameter.

[edit] Example

var sign = prompt("What's your sign?");
if (sign.toLowerCase() == "scorpio")
   alert("Wow! I'm a Scorpio too!");

When the user clicks the OK button, text entered in the input field is returned. If the user clicks OK without entering any text, an empty string is returned. If the user clicks the Cancel button, this function returns null.

[edit] Notes

A prompt dialog contains a single-line textbox, a Cancel button, and an OK button, and returns the (possibly empty) text the user inputted into that textbox.

Dialog boxes are modal windows - they prevent the user from accessing the rest of the program's interface until the dialog box is closed. For this reason, you should not overuse any function that creates a dialog box (or modal window).

Chrome users (e.g. extensions) should use methods of nsIPromptService instead.

[edit] Specification

DOM Level 0. Not part of any standard.

[edit] See also

alert, confirm