JavaScript 6e – Test Review Questions
Chapter 6: Enhancing and Validating Forms
True / False
	
1. While JavaScript lets you perform validation in a user’s browser, the server-side programs that receive form data generally perform validation as well.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
364	

2. By default, browsers create an collection of form objects that you can reference using array notation.
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
366, 367	

	

3. Assistive functions perform a type of validation.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
371	

4. You can use HTML to set the default value of a selection list so no option is selected.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
371	

5. Modern browsers can perform many validation tasks themselves without any extra JavaScript.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
394	

Multiple Choice	
6. To check if an option button is selected, you access the value of its ____ property.
 	
a. 	
marked	
b. 	
selected	

c. 	
checked	
d. 	
value	

REFERENCES:  	
418	

7. To display no default value on a selection list, you set its ____ property to -1.
 	
a. 	
selectedIndex	
b. 	
checked	

c. 	
selected	
d. 	
value	

REFERENCES:  	
371	

8. Many aspects of the way browsers present browser-based validation feedback are customizable through the properties and methods of the​ ____.
 	
a. 	
​Document Object Model	
b. 	
DOM tree	

c. 	
​​browser object model	
d. 	
​constraint validation API	

REFERENCES:  	
398	

9. The ____ event fires when a form is submitted.​
 	
a. 	
​clear	
b. 	
​blur	

c. 	
​input	
d. 	
​submit	

REFERENCES:  	
404	

10. You use the ____ method on an object to block the action normally associated with an event.​
 	
a. 	
​preventDefault()	
b. 	
​submit()	

c. 	
​checkValidity()	
d. 	
​select()	

REFERENCES:  	
405	

11. Which form element is useful for limiting user options to a set of choices?​
 	
a. 	
​textarea	
b. 	
​selection list	

c. 	
​text input box	
d. 	
​submit button	

REFERENCES:  	
369, 370	

12. You create an empty document fragment using the ____ method.​
 	
a. 	
​cloneNode()	
b. 	
​createElement()	

c. 	
​submit()	
d. 	
​createDocumentFragment()	

REFERENCES:  	
376	

13. Which attribute enhances usability in modern browsers?​
 	
a. 	
​id	
b. 	
​src	

c. 	
​placeholder	
d. 	
​value	

REFERENCES:  	
381	

14. What element property would you use when copying the contents of one text field to another text field?​
 	
a. 	
​value	
b. 	
​default	

c. 	
​content	
d. 	
​selectedIndex	

REFERENCES:  	
390, 391	

15. Which attribute toggles off validation of a form when added to the opening <form> tag?​
 	
a. 	
​validation	
b. 	
​submit	

c. 	
​novalidate	
d. 	
​nosubmit	

REFERENCES:  	
394	

16. Which type value for the input element triggers validation in modern browsers?​
 	
a. 	
​validate	
b. 	
​text	

c. 	
​number	
d. 	
​password	

REFERENCES:  	
394, 395	

17. In modern browsers, which attribute of an input element prevents the form from being submitted if the field is left blank?​
 	
a. 	
​novalidate	
b. 	
​required	

c. 	
​min	
d. 	
​max	

REFERENCES:  	
394	

18. Validation errors found by modern browsers are reported in​ ____.
 	
a. 	
separate browser windows	
b. 	
​the Address bar	

c. 	
​the Status bar	
d. 	
​bubbles	

REFERENCES:  	
396	

19. In general, modern browsers display validation feedback after the ____ event is triggered by a form.​
 	
a. 	
​submit	
b. 	
​reset	

c. 	
​validate	
d. 	
​check	

REFERENCES:  	
398	

20. You can use the CSS ____ pseudo-classes to change the properties of form elements based on their validity status.​
 	
a. 	
​:submit and :reset	
b. 	
​:hover and :blur	

c. 	
​:before and :after	
d. 	
​:invalid and :valid	

REFERENCES:  	
399	

21. To check a group of fields and trigger an error message if any of them is empty, you use a(n) ____ statement.​
 	
a. 	
​debugger	
b. 	
​loop	

c. 	
​console.log()	
d. 	
​submit	

REFERENCES:  	
410	

22. For any fields that require numeric values, you can use JavaScript’s built-in ____ function to determine whether a user actually entered a number.
 	
a. 	
​submit()	
b. 	
​reset()	

c. 	
​validate()	
d. 	
​isNaN()	

REFERENCES:  	
429	

23. When a control's value is found to be invalid during constraint validation, the ____ event is triggered.​
 	
a. 	
​input	
b. 	
​invalid	

c. 	
​change	
d. 	
​focus	

REFERENCES:  	
366	

24. Instead of document.getElementsByTagName("form")[0], you could use the code​
 	
a. 	
​document.forms[0]	

b. 	
​​document.form[0]	

c. 	
​document.getFormElements[0]	

d. 	
​​​document.forms.form[0]	

REFERENCES:  	
366, 367	

25. Use of the ____ attribute of the form element is not allowed in the strict DTD for XHTML.​
 	
a. 	
​id	
b. 	
​class	

c. 	
​name	
d. 	
​method	

REFERENCES:  	
367	

Completion	

26. __________ is the process of checking that information provided by users conforms to rules to ensure that it appropriately answers a form's questions and is provided in a format that the site's back-end programs can work with.​
REFERENCES:  	
364	

27. Enhancements to HTML and to modern browsers have allowed browsers themselves to perform many validation tasks without any extra JavaScript. This type of validation is known as __________ validation.
​REFERENCES:  	
394	

28. Creating a function to validate required fields generally involves retrieving the values of the required fields and checking if the value of any of them is​ __________.
REFERENCES:  	
408	

29. For all custom validation, it can be helpful to use the __________ structure​ for handling errors.
REFERENCES:  	
408	

30. To send the values entered in a form to a web server with JavaScript, you use the __________ method.​
REFERENCES:  	
365	

Subjective Short Answer	
31. How can you add options to a selection list with JavaScript?
REFERENCES:  	
375	

32. Describe two advantages of referencing form objects using methods such as getElementById() rather than the forms array.​
REFERENCES:  	
367	

33. In what situations can you get more accurate information on a form by ​using form fields other than text boxes? Name two types of fields you might use instead. 
REFERENCES:  	
369, 370	

34. What is an assistive function? Give an example of a situation in which you might use an assistive function.​
REFERENCES:  	
371, 374	

35. Describe how you can use JavaScript to simulate the behavior of the placeholder attribute in older browsers?.
REFERENCES:  	
382	

36. The requirements of the form you’re validating determine the kind of logic you need to incorporate into a custom validation program. However, a few types of validation functions are particularly common. Name two.​
REFERENCES:  	
402	

37. Why is is usually not necessary to include testing for the number of characters in user input in custom validation functions?​
REFERENCES:  	
404	

38. What does a function to validate required fields generally need to do?​
REFERENCES:  	
408	

39. Describe the three behaviors that make up the placeholder effect in modern browsers, and that you need to ​replicate with JavaScript for older browsers.
REFERENCES:  	
382	

40. If you were designing a form with a question that asked users if they had ever visited a certain city, would you expect more accurate input using a text input box or a check box? Why?​
REFERENCES:  	
369, 370, 371