Cover Image Erratas
Oops..
  


Sorry for the trouble that you are having with the Form Validation project in Chapter 4 of the book. This was a problem that I thought I had corrected, but it must have slipped by our final tech checks. There are two places that need slight modifications, first in the script and secondly in the HTML for the pulldown menu. In the script the line in question that needs fixing is following (it should be around line 52).

     if (document.forms['promotion'].elements['whatTheyWant'].value == 'default')


We need to first add a new line of code right before this one:

     var selectPos =
document.forms['promotion'].elements['whatTheyWant'].selectedIndex;

What this line does is to create a variable called "selectPos" and assigns it the value of whichever item is selected from the pull-down menu. Next we need to modify our IF statement to use this new variable.

     var selectPos =
document.forms['promotion'].elements['whatTheyWant'].selectedIndex;

     if
(document.forms['promotion'].elements['whatTheyWant'].options[selectPos].value == 'default')


In this newly modified IF condition we are checking to see if the value of the option for the selected menu item is equal to "default." If this is the case then we go ahead and execute the code that is contained within the IF statement. Now that we have the script fixed we need to change a line in the HTML (around line 249).

This is the existing piece of code:

     <OPTION VALUE="">Please choose a category

Here is what we need to change it to:

     <OPTION VALUE="default">Please choose a category


All we are doing here is assigning the value "default" to this initial menu item. This lets us test for our IF statement up in the script.


>