Media

INFO PAGE

Form Validation and Manipulation

Background

When users submit a form we often want to check what they are submitting. We can do this with JavaScript as an initial check BUT if we really care about testing, we need to test on the server side too as people can write their own forms on the client side without JavaScript validation and submit the data to your server.

Form validation often makes use of REGULAR EXPRESSIONS. We give a few examples below - see the code of this page (CTRL U).

In terms of form manipulation, you can get or set the value of any field by getting the field with document.getElementByID() and then set or get the value property. You can also change styles and add and remove fields, etc. using the DOM, Styles and Node manipulation shown in lesson 4.

Example

testing the message style