View Full Version : more Vorm Falidation ...

07-03-2002, 10:35 AM
Hi all,

OK, here's the thing. I have a couple of forms on my website and I'm attempting to write a single piece of general validation code to work on both of them. I'm attempting (and this is my first foray into this area) to use general document.forms.elements and iterating loops to do this.

1st, the call. The function is called from the onSubmit tag in the HTML - I pass the form name to identify the form we're working with:

onSubmit="return checkValidation('RequestForInformation');"

My actual validation code looks as follows:

requiredFieldsArray = new Array("Title","FirstName","Surname","Email","Company","Phone","ResearchPapers");

function checkValidation(formID)
{ formDOM = document.forms[formID];

for (i=0; i<=formDOM.elements.length; i++)
{ if (formDOM.elements[i].name == requiredFieldsArray[i])
{ if (formDOM.elements[i].type == "text")
{ if (formDOM.elements[i].value == "test") { alert("Please enter a value in the "+requiredFieldsArray[i]+" field"); return false; }
if ((formDOM.elements[i].type == "text")&&(requiredFieldsArray[i] == "Email")){}
if (formDOM.elements[i].type == "selection"){}
if (formDOM.elements[i].type == "checkbox"){}
return true;

However, there are two problems happening here:
1. in the Frontpage preview, afer I enter the value "test" and click Submit, I get the error :
formDOM.elements[...].name is null or not an object

2. when testing in a web browser, however, no errors come up at all and whn the sumbit button is pressed, my confirmation page is served up and it doesn't look like the onSubmit got anywhere near my validation code.

Could this be something to do with using the .name property on elements[i]? Is this not supported? Any ideas?

if you want to look at the working page, got to:
RequestForInformation.html (http://www.nemeaconsulting.co.uk/testarea/informationrequest.htm)



07-03-2002, 01:45 PM
Hi all,

fixed it - don't worry about it