Javascript problem..Please help

****EDIT*****I figured it out…I have:

var msg;

var missing;

It should be:

var msg = “”;

var missing = “”;

EDIT**

Hey guys…This is going to be kinda long. Bare with me…I can use some help…Right now its just validating 1 Field(ContactName).

If the Field is Blank and i click on the button the alert message comes up.

ALERTBOX

UndefinedPlease correct your entries…

-------------------------------Undefined

the following fields are missing:Undefined

-ContactName is a required Field.


ALERTBOX

I don’t understand why Undefined is there. It shouldn’t be.

Now if i add text to the ContactName Field and click the button, Internet Explorer shows me a javascript error message in the bottom left corner, that reads:

Line: 17

Char: 3

Error: ‘length’ in null or not an object

Netscape says: ‘Missing’ has no properties.

if(missing.length !=0)

Heres the javascript validation:

function validate(frm)

{

	var missing;

	var msg;

for(i=0; i<document.forms[0].elements.length; i++)    // loop through form elements

	{

	var el = document.forms[0].elements[i];

	if(el.required)

		{

	    if(isEmpty(el))

			{

			missing += "\n   - " + el.name + " is a required field";

			}

		}

	} 

// build output message

if(missing.length !=0)

	{

	if(missing.length !=0)

		{

		msg += "\n\nThe following required fields are missing:";

		msg += missing;

		}

	errMsg(msg);           // call the output function

	msg = ""; missing = ""; // reset all our variables

	return false;

	}

else

	{

	return true;

	}

}

function isEmpty(field)

{

str = field.value;

if(str == "") 

	{

	return true;

	}

else

	{

	for(j=0; j<str.length; j++)

		{

		if(str.charAt(j) != " ")

			{

			return false;

			}

		}

	}

return true;

}

function errMsg(msg)

{

var theMsg = "You entered some incorrect values into the form. ";

theMsg += "Please correct your entries then re-submit the form.\n";

theMsg += "____________________________________________________________________";

theMsg += msg;

theMsg += "\n____________________________________________________________________\n";

alert(theMsg);

}

In the button i have:

document.forms[0].ContactName.required = true;

return validate(document.forms[0]);

Any suggestiong would be very helpful…Thanks a bunch guys!!!

-Jordan