Java Reference
In-Depth Information
This has two errors. First, value is a property and not a method, so there is no need for parentheses
after it. Second, you have the all-time classic error of one equals sign instead of two. Remember that one
equals sign means “Make it equal to,” and two equals signs mean “Check if it is equal to.” So with the
changes, the line is:
if (theForm.elements[elementCount].value == “”)
The next error is the failure to put your block of if code in curly braces. Even though JavaScript won't
throw an error since the syntax is fi ne, the logic is not so fi ne, and you won't get the results you expect.
With the braces, the if statement should be as follows:
if (theForm.elements[elementCount].value == “”)
{
alert(“Please complete all form elements”)
theForm.elements[elementCount].focus;
formValid = false;
break;
}
The penultimate error is in this line:
theForm.elements[elementCount].focus;
This time you have a method but with no parentheses after it. Even methods that have no parameters
must have the empty parentheses after them if you intend to execute that method. So, corrected, the line
is as follows:
theForm.elements[elementCount].focus();
Now you're almost done; there is just one more error. This time it's not something wrong with what's
there, but rather something very important that should be there but is missing. What is it? It's this:
elementCount++;
This line should be in your while loop, otherwise elementCount will never go above 0 and the while
loop's condition will always be true, resulting in the loop continuing forever: a classic infi nite loop.
Chapter 5
Exercise 1 Question
Using the Date type, calculate the date 12 months from now and write this into a web page.
Exercise 1 Solution
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
Search WWH ::




Custom Search