Web Development and Design Foundations with XHTML, 5th Edition

(Steven Felgate) #1
Answers^653


  1. The code might look something like the following:
    if (userAge < 18)
    {
    alert("You are under 18");
    } else {
    alert("You are 18 or older");
    }

  2. 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



  1. 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.

  2. 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.

  3. 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



  1. a

  2. c

  3. b

  4. a

  5. d

  6. c

  7. a

  8. b

  9. c

  10. a

  11. browser sniffing

  12. jump menu

  13. window

  14. variable

  15. onclick

  16. Common uses for JavaScript
    include rollover images, form data
    validation, popup windows,


browser sniffing, interactivity such
as alert messages and prompts, and
mathematical calculations.


  1. 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.

Free download pdf