

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use JavaScript to show a confirm message?
A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: Cancel.
If the user clicks on the OK button, the window method confirm() will return true. If the user clicks on the Cancel button, then confirm() returns false.
Example
You can try to run the following code to implement confirmation dialog box in JavaScript:
<html> <head> <script> <!-- function getConfirmation(){ var retVal = confirm("Do you want to continue ?"); if( retVal == true ){ document.write ("User wants to continue!"); return true; } else{ document.write ("User does not want to continue!"); return false; } } //--> </script> </head> <body> <p>Click the following button to see the result: </p> <form> <input type="button" value="Click Me" onclick="getConfirmation();" /> </form> </body> </html>
- Related Questions & Answers
- How to show a dialog to confirm that the user wishes to exit an Android Activity?
- How to change button label in confirm box using JavaScript?
- How to center the JavaScript alert message box?
- How to show hyperlinks in JavaScript alert?
- How to confirm before stopping the process in PowerShell?
- How to show for loop using a flowchart in JavaScript?
- How do I print a message to the error console using JavaScript?
- How to show prompt dialog box using JavaScript?
- How to hide/show HTML elements in JavaScript?
- How do I display image in alert/confirm box in JavaScript?
- How to show a while loop using a flow chart in JavaScript?
- How to show if...else statement using a flowchart in JavaScript?
- How to show the full URL of a document with JavaScript?
- JavaScript Error message Property
- How to display message from a stored procedure?
Advertisements