prompt method (window)
Displays a prompt dialog with a message, an input field, an OK and a Cancel button.
Script execution does not continue until the prompt method returns (the user presses the OK or the Cancel button or closes the prompt dialog).
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Optional. String that specifies the text for the message in the dialog box. Default is an empty string. | |||||||
Optional. String that specifies the default value of the input field. If not specified, the input field will be empty in Firefox, Opera, Google Chrome and Safari, and will contain 'undefined' in Internet Explorer. |
Return value:
If the prompt dialog was closed by the Cancel button or by the system Close button, the prompt method returns null in Internet Explorer, Firefox, Google Chrome and Safari, and returns undefined in Opera. Otherwise, the prompt method returns a string that represents the value of the input field at that time when the prompt dialog was closed.
Example HTML code 1:
This example illustrates the use of the prompt method:
|
||||
<head> <script type="text/javascript"> function GetName () { var answer = prompt ("What is your name?", "Anonymus"); // undefined == null, but '' != null if (answer == null) { alert ("Your did not specify your name!"); } else { alert ("Your name is: " + answer); } } </script> </head> <body> <button onclick="GetName ()">Specify your name!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments