3. Getting Input

3.1. Using a Confirm Box


          A confirm box is usually used when a user wants to check or approve something. Confirm box will pop up in the user’s browser and allow them to select between “OK” or “Cancel” in order to continue. If an “OK” is selected, the box will return true while if “Cancel” is selected, it will return false.

          In the sample code given, a button is created. This button will perform a certain action once clicked. As you can see in the script, a function is added. This function will be executed with the button being clicked. Inside the function, a conditional statement (if-else) is added. The condition in the if statement requires the user to press a button from the confirm box. If the user presses the ‘OK’ button, the condition will return true and execute whatever is inside the if statement. However, if ‘Cancel’ is pressed, the condition is false and will execute the code inside the else statement. More details on how this conditional statement works will be discussed in the succeeding topic.