var players = 0;
while (players < 1 || players > 2)
players = prompt("Enter number of players (1 or 2)", 1);
if (players == 2) alert("Choose your partner!");
confirm
Displays a Confirm dialog box with the specified message and OK and Cancel buttons
Method of
window
Implemented in
JavaScript 1.0
Syntax
confirm(message)
Parameters
message
A string.
Examples
This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp function closes the application.
function confirmCleanUp() {
if (confirm("Are you sure you want to quit this application?")) {
cleanUp() }
}
another example
function confirm_url (message, next_url) {
confirm_result = confirm(message);
if (confirm_result == true) {
document.location = next_url;
return true;
} else { }
}
See also
window.alert, window.prompt