Answers^653
- The code might look something like the following:
if (userAge < 18)
{
alert("You are under 18");
} else {
alert("You are 18 or older");
} - A function definition begins with the keyword function, followed by the name
of the function, and some JavaScript statements. It defines a function and calling
that function results in the execution of the statements within it.
Checkpoint 14.4
- Form data validation refers to checking form input against validation rules and
not allowing the form to submit if the data does not conform to the rules. - Answers may vary, but may include required fields such as name, e-mail address,
and phone number. Numeric fields may require validation to ensure that they are
within particular bounds such as order quantity greater than 0 and age between
1 and 120. - When the user clicks the submit button, the submit event occurs and the onsubmit
event handler executes the return validateForm()command. The validateForm
function runs and tests the form data for validation. If the data is valid,
validateForm()returns the value of true, and the form submits. If the data is
not valid, validateForm()returns the value of falseand the form does not
submit.
Review Questions
- a
- c
- b
- a
- d
- c
- a
- b
- c
- a
- browser sniffing
- jump menu
- window
- variable
- onclick
- Common uses for JavaScript
include rollover images, form data
validation, popup windows,
browser sniffing, interactivity such
as alert messages and prompts, and
mathematical calculations.
- The following techniques can be
used when debugging JavaScript.
Check the JavaScript code carefully
for syntax errors. Verify that quo-
tation marks, braces, and parenthe-
ses are used in pairs. Check for
missing semicolons. Verify that
your code uses the correct case
(uppercase and lowercase charac-
ters) in variable, object, property,
and method names. Use the
JavaScript Console to help with
debugging—it will provide some
information about the error. Use an
alert()to display the values of
variables or to display messages as
your script is running.