Javascript examples for Browser Object Model:Window confirm
The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.
Parameter | Type | Description |
---|---|---|
message | String | Optional. Specifies the text to display in the confirm box |
A Boolean, indicating whether "OK" or "Cancel" was clicked in the dialog box:
The following code shows how to Display a confirmation box:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from ww w . ja v a2 s.c o m*/ var txt; var r = confirm("Press a button!\nEither OK or Cancel.\nThe button you pressed will be displayed in the result window."); if (r == true) { txt = "You pressed OK!"; } else { txt = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>