Let's expand this example with a more complex function that checks lots of form fields.
We'll also look at how to check other types of fields, such as checkboxes, radio buttons and drop-down lists.
The form is large so I didn't want to paste all here, but the snap shot of the items I'm referring to are: Is it possible to make the the text field with name=googlekey required if some selects Google Search in drop down..not required if they make some other selection? The name of the function is validate Form() for a solution to trapping the space being entered. I get my form to work with the validation, but everyone who first submits the form gets this error: "403 No variable substitutions in template"When you reload the page the form sends perfectly. "\n"), then display the final string in an alert box if valid == false. It has three fields which I want to validate but in testing it the first incident of validation causes the alert to pop up but then when I click OK on the alert it submits the form anyway without letting me complete the field and continue to the other fields.
Thanks, David[Edited by catron on 16-Feb-11 ] im having trouble with my student registration form.you choose the subjects BSIT, BSMATH, BSED, BEED.year level will be limited until 4 year only while if course is BSCE, BSGE, BSArch it will limit until 5 year.. [code]if ( document.contact_form.contact_name.value == "" ) [code]=space In your example if one enters    it does not trap it. It can be found at; Matt, I find your site very helpful. Validation is working when I test the forms but I am getting emails with 1 or -1 in fields (instead of a valid phone or email, etc.) AND I am getting 20, 40, 80 at one time.
Let's look at a more complex validated form with some different types of form fields. Try pressing the Send Details button without filling in the form and see what happens.
Again, you might like to open the source code for this form in a separate window, so that you can refer to it as we talk you through.
One point to note about Java Script validation is that it can always be circumvented by the user disabling Java Script in their browser, so for secure validation you'll need to write your validating code in your server-side scripts.
However, for day-to-day use Java Script is a quick and easy way to check over your forms before they're sent to your server.
Our example script works by validating all the form fields at once.
You can see that the page consists of a Java Script function called That's all there is to simple Java Script form validation!
Our example is very simple as it only checks one field.
I have a dropdown selection list, and based on the selection, there are text fields that are hidden or displayed for more info.