function problem

Giganews Newsgroups
Subject: function problem
Posted by:  Dwayne Epps (dwayneeppsNOSP…
Date: Thu, 17 Jul 2003

This is probably a no brainer, but I am having no luck at getting this to
work.  I'm creating functions that will validate form data fields.  For
example, the following function:

function checkText(field, msg, min, max) {
if (!min) { min = 1 }
if (!max) { max = 65535 }
if (!field.value || field.value.length < min || field.value.max > max ||
!field.value.match(/^[a-zA-Z]*$/)) {
return false;
}return true;

I tested the above function and it works great.  The problem is I have
several different functions that will check for fields with different data
like: numbers only, selections in drop down menus, valid zip code, etc.  I'm
trying to create one function that I can call using the onSubmit event that
will go through each function to validate all the fields in the form.

I was trying to use the following function to accomplish this using just the
first function.  I would include other if statements for the other

function formValidation(thisform) {
if (checkText(this.first_name, 'Please enter your first name.', 2,
15)==false) {
return true;
return false;

then within the form tag, I called the function: onSubmit="return

I'm not all that proficient with Javascript as I'm still learning.  Can
anyone identify my mistake in the formValidation function?  The argument
"thisform" doesn't need to be the name of the HTML form does it?  I thought
it could be any name of my choosing?  Any help is greatly appreciated.
Thanks in advance.