The "this" Keyword

Return to the contestform.html file in your text editor and go to the <INPUT> tag for the Bold field. In the code onBlur="PERS();" type the word this within the parentheses as follows:

<INPUT NAME=BOLD VALUE=0 SIZE=1 MAXLENGTH=1 onBlur="PERS(this);">

Repeat inserting the word this in the remaining eight category fields. Save your changes.

Now that you have added the "this" keyword, you need to make several changes to the function itself. First, the function must store the value of the active field in a variable. Then it needs to test whether or not the value of that variable is equal to 0, 1, 2, 3, 4, or 5. If it is, the function can calculate the total PERS score as before; is not, the function should alert the user that a mistake has been made and return the cursor to the appropriate field so that the user can enter the correct value.

Return to the PERS() function in the head section of your HTML file. In the line"function PERS() {" type the word field within the parentheses. Add the following two lines below the function PERS(field) } (indented three spaces to make the code easier to follow):

var score = field.value;

if(score==0 || score==1 || score==2 || score==3 || score==4 || score==5) {

The | symbol is often located above the \ symbol on your keyboard. You can type it by pressing the \ key while holding down the Shift key.

Insert the following commands above the last line (the closing brace}) of the function (indented three spaces):

} else {

//alert the user

field.focus();

}

Your PERS() changes should look like the following:

function PERS(field) {

var score = field.value; if(score==0 || score==1 || score==2 || score==3 || score==4 || score==5) {

var B = eval(document.CON.BOLD.value);

var C = eval(document.CON.CRUNCHY.value);

var R = eval(document.CON.RICH.value);

var M = eval(document.CON.CREAMY.value);

var T = eval(document.CON.SMOOTH.value);

var S = eval(document.CON.SUBTLE.value);

var F = eval(document.CON.FRUITY.value);

var A = eval(document.CON.TART.value);

var G = eval(document.CON.TINGLING.value);

document.CON.TOTAL.value = B + C + R + M + T + S + F + A + G;

} else {

//alert the user

field.focus();

}

}

Save your changes.