Let's have a look at the code which will create a confirmation dialog box with an alert of what user click in the dialog box.
- <html>
- <body>
- <p>Click the button to display a confirmation box.</p>
- <button onclick="myBox()">Click it</button>
- <p id="function"></p>
- <script>
- function myBox()
- {
- var x;
- var y=confirm("Click a button!");
- if (y==true)
- {
- x="You clicked OK button!";
- }
- else
- {
- x="You clicked Cancel button!";
- }
- document.getElementById("function").innerHTML=x;
- }
- </script>
- </body>
- </html>
Output
After clicking the button the dialog box will be shown.
When you click the OK or Cancel button the following output will be shown.