Making of Confirmation Pop-Up Dialog Box Through JavaScript

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.
  1. <html>  
  2. <body>  
  3. <p>Click the button to display a confirmation box.</p>  
  4. <button onclick="myBox()">Click it</button>  
  5. <p id="function"></p>  
  6. <script>  
  7. function myBox()  
  8. {  
  9. var x;  
  10. var y=confirm("Click a button!");  
  11. if (y==true)  
  12. {  
  13. x="You clicked OK button!";  
  14. }  
  15. else  
  16. {  
  17. x="You clicked Cancel button!";  
  18. }  
  19. document.getElementById("function").innerHTML=x;  
  20. }  
  21. </script>  
  22. </body>  
  23. </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.
 
                     
 
Ebook Download
View all
Learn
View all