A CONFIRM box is used when you are trying to get a YES / NO answer from the visitor. The OK button acts as the YES response the CANCEL button acts as the NO response.

To get the CONFIRM actions to perform, we have to use a VARIABLE situation to control it. That means, we have to use a bit of algebra to temporarily assign a value to the visitor's answer choice. After the value (answer) is determined, the script then carries out the set of instructions accordingly. This is usually done with an IF...ELSE statement. IF the answer is true, do this. ELSE the answer is false, so do this instead.

Here is the code used for my example:

VAR means VARIABLE. A temporary storage place.

ANSWER is the name of that storage place. Depending on the visitor's response, the ANSWER will hold either a TRUE or FALSE value.

CONFIRM creates the actual pop-up box with an OK and CANCEL choice. OK is used for a TRUE response. CANCEL is used for a FALSE response. The text area following is used as the prompt text on the box. Usually a true/false type question.

IF( ) ELSE. This determines what happens according to the input. It looks at the storage cell called ANSWER. IF it is a TRUE value, it does the first set of instructions. ELSE it is a FALSE value, so do this other set of instructions.

The CONFIRM pop-up can be used to direct the visitor to a specific page or site depending on the choice too. Here is an example that uses the CONFIRM to ask IF the visitor would like to continue into the site, or be directed to the Yahoo site. This is placed in the HEAD area of the coding :

Since the code is in the HEAD area, it is read and implemented before the loading of the actual page in the BODY area.

Notice the ! before the word answer in the IF statement. That means NOT. Normally a confirm question is looking for the OK answer. To find the CANCEL answer, we have to tell it to look for a negative answer, or NOT. It then carries out the instructions as : IF this statement is true, THEN do this set of instructions, otherwise carry on and load the page.

window.location tells the browser to load the following URL address into the current browser window location. Since it will be loading in the new URL, the page with the CONFIRM box will be left behind.

Table of Contents