Easy Tutorial
❮ Met Win Cleartimeout Obj Location ❯

Window prompt() Method


Definition and Usage

The prompt() method is used to display a dialog box that prompts the visitor for input.

This method returns the string input by the user.

Syntax

Parameter Description
msg Optional. Plain text to be displayed in the dialog box (not HTML formatted text).
defaultText Optional. The default input text.

Browser Support

All major browsers support the prompt() method.


Example

Display a prompt box asking for her/his name, then write a greeting on the page:

function myFunction(){ 
    var x; 
    var person = prompt("Please enter your name", "Harry Potter"); 
    if (person != null && person != ""){ 
        x = "Hello " + person + "! How are you today?"; 
        document.getElementById("demo").innerHTML = x; 
    } 
}

❮ Met Win Cleartimeout Obj Location ❯