Javascript Confirm Boxes

Javascript Confirm Boxes differ from Javascript Alerts in one way. They give the user two options; 'OK' and 'Cancel'. Obviously you can use this when coding functions, which I'll lightly touch upon here.

To create a Javascript Confirm Box, use the following code which will be explained later.

The '<script type="text/javascript">' part notifies the browser that the code ahead will be written in Javascript. The 'confirm("This is a confirm Box");' parts tells the browser to create a confirm box, reading 'This is a confirm Box'. Finally, the '</script>' part notifies the browser to quit Javascript mode, and return to normal HTML Mode.

If you wish to base an action depending on whether the user clicks 'OK' or 'Cancel', modify the following code, which as usual, will be explained later.

Seeing as I've explained parts of the code before, I'll just explain the new elements. The 'var a = confirm("Press A Button");' part sets a variable named 'a' and executes the variable. Then, the 'if(a==true){' asks whether the variable named 'a' returned true (Eg. Pressing 'OK'). If it did, it executes everything between the two parythensis (alert("You Pressed OK!");). The 'else{' asks if the above if statement executed. If it didn't, everything between the else's two parythenses execute (alert("You Pressed Cancel!");).

Line breaks also work in Confirm Boxes, see the above tutorial on how to do it.