free hosting   image hosting   hosting reseller   online album   e-shop   famous people 
Free Website Templates
Free Installer

Using Confirm Boxes


A confirm box is similar to an alert box, except that it has 2 options: OK and Cancel.

Here's a simple example:


Try It
Pressing the OK button generates the "Thank You" alert box.

Pressing Cancel (or closing the confirm window) generates the "Sorry" alert.


Using onLoad and onUnload

As with popup windows, these commands can be used to generate confirm boxes on entering or leaving a page:

onLoad:
onUnload:
For the 2 above examples, add the following to the body tag:
In both examples, the confirm boxes allow you to perform a real action - in these instances, the option to open another page in a new window.

With the onUnload example, nested if(confirm ...) statements are used.

You can do this as many times as you like, but it can be rather infuriating if overdone.

Also, a line break, \n, is introduced for the final goodbye confirm box.

This is not necessary, but merely to give the box a nicer appearance.




© 2001 CyberSchool
Last Update: