JavaScript Modals - Prompts Usage of prompt()


Example

Prompt will display a dialog to the user requesting their input. You can provide a message that will be placed above the text field. The return value is a string representing the input provided by the user.

var name = prompt("What's your name?");
console.log("Hello, " + name);

You can also pass prompt() a second parameter, which will be displayed as the default text in the prompt's text field.

var name = prompt('What\'s your name?', ' Name...');
console.log('Hello, ' + name);
ParameterDescription
messageRequired. Text to display above the text field of the prompt.
defaultOptional. Default text to display in the text field when the prompt is displayed.