DOM Window.prompt() Method
The prompt() method shows a dialog asking the user to type some text, and returns what they entered or null.
Description
The prompt() method displays a modal dialog with a message and a text box, returning the entered string, an empty string if they entered nothing, or null if they cancelled. It blocks the page and can't be styled or validated, so a form or <dialog> is better for real input.
The returned value is always a string (or null), so convert it with Number() if you asked for a number, and validate it, since users can type anything. Like alert() and confirm(), it pauses all scripts while open and is blocked in sandboxed iframes.
Because it can't be styled, labelled properly or validated as the user types, a form field, or a form inside a <dialog>, is a better choice for anything users see in production.
Syntax
prompt(message)
prompt(message, defaultValue)Parameters
- messageThe text to show.
- defaultValueOptional. The initial text in the input box.
Return Value
The text the user entered, or null if they cancelled.
Example
Browser Support
The following information will show you the current browser support for the Window.prompt() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





