Validating User Input

You want ensure that only the values 0, 1, 2, 3, 4, or 5 to be entered into the PERS component fields. Therefore, you have to include some way of checking the participant's entries in these fields to make sure that they are valid. If the user enters an incorrect value in one of the component fields, two things must happen:

  1. The browser should display a dialog box informing the user of the mistake.
  2. The cursor should be positioned back in the field in which the user entered the incorrect value, preventing the user from leaving the field until a valid value has been entered.

This presents a problem because nine different component fields could be accessing the PERS() function at any time. To make this work, you have to pass information to the function, indicating which field is using it. You do this with the "this" keyword.