Form validation

Unit 18

Validation at entry

You can validate the data, as the user enters the data. Invoke your validation function from the element's onchange, onclick, or other similar event. This allows prompt feedback to the user

Validation onsubmit

You can validate the fields in a form when the form is submitted. Call your validation function from the onsubmit attribute value in the form element.

It is usually good to validate a form when it is submitted, even if individual fields are validated as they are entered.

Validation in the server

Validation of a form in the server is essential.

The forms submitted from the client are sent to the web server. The reason the server must always validate the input data, is because you never know where the incoming junk is coming from. You may expect to receive it from a web page that you have set up to validate the data; but, it could come from somewhere else.

We are not writing server code in this class.

Validation sample

If you provide the attribute multiple="multiple" in the select element, the select list allows selection of multiple options.

In this case, you will need to search the options[] array to see which select objects have their selected property set to true.

Sample 5 shows processing of multiple selections in a select list.

Summary

  • Validation as the data, when is entered into a form, is optional.
  • Validation of the form in the client, when it is submitted, is very good.
  • Validation of a form in the server, when it is received, is required.

Reading assignment

Reading assignments are in the text book, Java Script, A Beginner's Guide, Second Edition, by John Pollock; McGraw Hill / Osborne, ISBN 0-07-222790-7

There are no additional reading assignments.

Alternate reading assignments are in the text book, Java Script Concepts & Techniques Programming Interactive Web Sites, by Tina Spain McDuffie; Franklin, Beedle & Associates, ISBN 1-887902-45-7

Read Chapter 13 Validating forms.

Lecture notes

Do NOT read the lecture notes before hearing the lecture. If you do, you will find the lecture very boring. Read the lecture notes if you do not attend the lecture, or if you wish to review the material.