How to get my JS Header to work? - added that now what?

Hello - I have the code below in the JS Header of my form, however when I click submit nothing happens. What am I missing to get this code to run and verify that the fields are filled in? I don’t know JS very well and copied this from an other form that it does work on. I just updated the else if statements with my field names. Thanks much!

var F = document.forms[0]

var whitespace = " \t\n\r";

var defaultEmptyOK = false

var tempint

function fnsubmit()

{

if(isValid())	{

document.forms[0].ReturnURL.value = document.location

document.forms[0].navAction.value = "initial"

document.forms[0].submit()

}

}

function isValid()

{

if (document.forms[0].Name.value == ""){

	alert("Please enter the Donor's Name.")

	document.forms[0].Name.focus();

	return false;

}

else 	if (document.forms[0].Address.value == ""){

	alert("Please enter the Donor's address.")

	document.forms[0].Address.focus();

	return false;

}



else 	if (document.forms[0].City.value == ""){

	alert("Please enter the Donor's city.")

	document.forms[0].City.focus();

	return false;

}

else 	if (document.forms[0].State.value == ""){

	alert("Please enter the Donor's state.")

	document.forms[0].State.focus();

	return false;

}



else 	if (document.forms[0].Zip.value == ""){

	alert("Please enter the Donor's zip code.")

	document.forms[0].Zip.focus();

	return false;

}

else 	if (document.forms[0].Phone.value == ""){

	alert("Please enter the Donor's phone number.")

	document.forms[0].Phone.focus();

	return false;

}

else 	if (document.forms[0].Fax.value == ""){

	alert("Please enter the Donor's fax number.")

	document.forms[0].Fax.focus();

	return false;

}

else 	if (document.forms[0].Email.value == ""){

	alert("Please enter the Donor's email address.")

	document.forms[0].Email.focus();

	return false;

}

	else 	if (document.forms[0].BName.value == ""){

	alert("Please enter the Broker's name.")

	document.forms[0].BName.focus();

	return false;

}

		else if (document.forms[0].BFirm.value == ""){

		alert("Please enter the Broker's firm.")

		document.forms[0].BFirm.focus();

		return false;

		}

		else if (document.forms[0].BNum.value == ""){

		alert("Please enter the Broker's phone number.")

		document.forms[0].BNum.focus();

		return false;

		}

		else if (document.forms[0].DonAcctNum.value == ""){

		alert("Please enter the Donor's account number.")

		document.forms[0].DonAcctNum.focus();

		return false;

		}

		else if (document.forms[0].SName.value == ""){

		alert("Please enter the Stock Name.")

		document.forms[0].SName.focus();

		return false;

		}

		else if (document.forms[0].NumShares.value == ""){

		alert("Please enter the number of shares.")

		document.forms[0].NumShares.focus();

		return false;

		}

		else if (document.forms[0].Designation.value == ""){

		alert("Please enter the Penn State designation.")

		document.forms[0].Designation.focus();

		return false;

		}

return true;

}

Subject: Where is the function called?

Make sure that the function is called.Check the onSubmit event of your form or the onClick event of the submit button.

Subject: How to get my JS Header to work?

In the onSubmit event of the form, enter the following:

return fnsubmit()

/Peter

Subject: RE: How to get my JS Header to work?

Do I have to do anything special to my Submit button on my page? I added the return fnsubmit() to my onSubmit and it threw the first error, but then went ahead to “form processed”

Subject: RE: How to get my JS Header to work?

Patty,

Option 1)

Take the code out of the onSubmit()

In your submit button… make it call fnSubmit()

The theory is that if the document is valid… it will call the submit action.

Option 2)

Change fnSubmit:

function fnsubmit()

{

if(isValid()) {

document.forms[0].ReturnURL.value = document.location

document.forms[0].navAction.value = “initial”

return true;

} else {

return false;

}

}

I removed the submit code from fnSubmit (considering you’re calling fnSubmit from the onSubmit it’s redundant). It will also return the correct boolean to the onSubmit().

Subject: RE: How to get my JS Header to work?

I took the code:function fnsubmit()

{

if(isValid()) {

document.forms[0].ReturnURL.value = document.location

document.forms[0].navAction.value = “initial”

return true;

} else {

return false;

}

}

and put it in the onClick of my button and selected Web where it says (Run) and JavaScript as the type. Now my button does nothing???

Subject: RE: How to get my JS Header to work?

Patty,

Put the fnSubmit code (the one you just posted about) and put it back in the JSHeader.

in the onSubmit… make sure it calls return fnSubmit()

in the button… all you should call is the submit document.forms[0].submit()

Subject: RE: How to get my JS Header to work?

Thank you.