Notifying the User with Alert and Confirm Dialog Boxes
If the user enters an incorrect value for one of the PERS components, the form should display a dialog box informing the user of the error. To accomplish this, you can use the alert() method. The alert() method operates in the same way as the prompt() method, except that is does not provide an input box in which the user can type a response. Instead, it simply displays a dialog box containing a message. The syntax for the alert() method method is:
where Message is the message that will appear in the dialog box.
In the PERS() function, replace the comment "//alert the user" with the following line of code:
alert("You must enter a 0, 1, 2, 3, 4, or 5");
Save your changes, and then reopen the file in your Web browser. To test the revised PERS() function, you'll attempt to enter an incorrect value in the Bold field. Click the Bold input box and change its value from the default of 0 to 5, and then press the Tab key. Your Web browser should display a dialog box. Click the OK button. Your cursor is returned to the Bold input box. Note that you cannot tab out of this box or click outside it without receiving the error message. Change the value in the Bold input box to 5, and then press the Tab key. The cursor advances to the Crunchy input box. Attempt to enter values greater than 5 in the other component input boxes and verify that the alert dialog box opens when you do so.
Congratulations, you have become a master at completing forms!!!!