/

HTML / CSS / JavaScript Tutorial

JavaScript Window method: prompt()

[this page | pdf | back links]

The prompt() method (when applied to Window objects in the JavaScript BOM) displays text in a dialog box prompting user for input (and with an OK and Cancel button).

 

It has the following syntax with the following parameters. It returns a string if the user clicks OK, being the input value (an empty string if the user didn’t input anything), or null if the user clicks cancel.

 

window.prompt(text, defaulttext)

 

Parameter

Required / Optional

Description

text

Required

String specifying text to display in dialog box

defaulttext

Optional

String specifying default input text

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile