JavaScript » Window » prompt

Syntax:
window.prompt(message[, defaultInput])
defaultInput
This optional parameter specifies the text that initially appears in the input field.

This method displays a dialog box prompting the user for some input.

Examples

Code:
<body onload=greeting()>

<script type="text/javascript">
function greeting() {
    y = (prompt("Please enter your name.", "Type name here"))
    document.write("Hello " + y)
}
</script>
Explanation:

This example prompts the user for their name and then writes a personalized greeting to the page.