Validate multiple fields that have same name

Hi

I am trying to validate the text fields in this form.

<input name="Answer[]" type="text" id="Answer[]" />
              </label></td>
            </tr>
            <tr>
              <td>Option2:</td>
              <td><input name="Answer[]" type="text" id="Answer[]" /></td>
            </tr>
            <tr>
              <td>Option3:</td>
              <td><input name="Answer[]" type="text" id="Answer[]" /></td>
            </tr>
            <tr>
              <td>Option4:</td>
              <td><input name="Answer[]" type="text" id="Answer[]" /></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><label>
                <input type="submit" name="Submit" value="Submit" />

In my head section I have

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

function validate() {
var theMessage = "Please complete the following: \
-----------------------------------\
";
var noErrors = theMessage

// make sure field is not blank
for (i = 0; i < document.form1.Answer.length; i++) {
if (document.form1.Answer[i].value=="")
theMessage = theMessage + "\
 --> You must enter an answer";
}
// If no errors, submit the form
if (theMessage == noErrors) {
return true;
} else {
// If errors were found, show alert message
alert(theMessage);
return false;
}
}
// End -->
</script> 

and on the form I have

onSubmit="return validate(this);"

theForm.elements will give you an array of the elements. You can loop through it and check the name of each element to see if it has the correct name.

Thanks for the reply.

I got this working:

<script type="text/javascript">

	function validate(){

		var AnswerInput = document.getElementsByName('Answer[]');
		for (i=0; i<AnswerInput.length; i++)
			{
			 if (AnswerInput[i].value == "")
				{
			 	 alert('Complete all the fields');		
			 	 return false;
				}
			}
	}

</script>