January 2018
Intermediate to advanced
678 pages
20h 16m
English
reset and focus MethodsGo back to Figure 8.9B, and you can see that we still haven’t talked about the last two lines in the generateEmail function. Here are those lines:
form.reset(); form.elements["first"].focus();
The form object’s reset method reassigns the form’s controls to their original values. Because the Email Address Generator web page has no value attributes for its text controls, the reset method call assigns empty strings to the text controls, thereby blanking them out.
When an element object calls the focus method, the browser puts the focus on the element’s control if it’s possible to do so. For text control elements, like the first-name text control retrieved in the preceding code, putting the focus on it means the browser ...
Read now
Unlock full access