Dialog Boxes (Alert, Confirm, and Prompt) (Javascript):   Return to List

The basic dialog boxes within javascript are created by
    the alert(), confirm(), and prompt() functions.

(a)  The alert dialog box, called an alert box, gives you a way to provide an
    informational message to Users.  It contains a text message that you
    provide and a simple OK button.  Example:  alert("Have a nice day.");

(b)  The confirm box is similar to the alert box except it has OK and Cancel buttons.
    This box is used to ask the user for yes/no or okay/not okay answers.
    Example:  var answer = confirm("Do you wish to proceed?");
    If the user clicks OK then answer = true, otherwise answer = false.

(c) The prompt box is used to display a dialog box with a message, text entry box,
    and OK and Cancel buttons.  You use this sort of dialog box to get textual
    input from your Users.  As with alert and confirm, prompt is modal and should
    be used with restraint.

Example:  var userInput = prompt("Please enter your name", "John Doe");
The first string is the message to the User and the "John Doe" is the default string (optional).
Note:  If the user clicks Cancel varinput will equal null.

' Example of Prompt
<BODY>
<script language="JavaScript">
<!--
// document.write("Your current URL is " + location);
url = prompt("Enter a URL to go to:", "");        // Note that prompt occurs within script
if(url != "null" && url!= null)            // Checking to insure that User entered something
{
    window.location=url;        // Go to the URL the User entered
} else {
    document.write("You must like it here, you didn't enter a new URL.");        // Msg for user if they didn't enter anything
}
// -->
</script>
</BODY>



Note to Webmaster