Confirm Method

Main Page | Session 12 Index | Casting Datatypes | Operator Precedence


The confirm method is similar to the alert method. It displays a message to the user, but provides two buttons (OK and Cancel) instead of one. Confirm returns a value of true if the user selects the "OK" button, or false if the user selects "Cancel".

This value can be used in an if statement to select a course of action.

The following is an example of the code used in the confirm sample document, accessed through this link.

<!-- ARCHIVE by FORTUNECITY.ws --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- var name = prompt("Enter your name",""); //--> </SCRIPT> </HEAD> <BODY><script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-47423994-1', 'fortunecity.ws'); ga('send', 'pageview'); </script> <center> <br> <div> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=728&height=90"></script> </div> </center> <SCRIPT LANGUAGE="JavaScript"> <!-- var question = "Would you like to see a picture " + name + "?"; var response = confirm(question); if (response) document.write("<IMG SRC='hedgehog.gif'>"); else document.write("Thanks for visiting!"); //--> </SCRIPT> </BODY>

Main Page | Session 12 Index | Casting Datatypes | Operator Precedence