Hi there,
Can anyone see the reason why the length of “…question…” form elements which in my form are dialog list keep showing up as having an undefined length within the following code?
var form = document.forms[0];
// Outer loop moves through the fields/elements of the form
for (var h=0; h < form.elements.length; h++) {
var element = form.elements[h];
//var eName = element.name;
alert("*E length: " + element.length + " E name: " + element.name);
// Checks if the field name begins with 'question' and isn't the same as the previous field name
if((element.name.substring(0, 8) == "question") && (form.prevElement.value != element.name)) {
//alert("in" + eName + " : prev " + form.prevElement.value);
// Check to see if an option has been chosen
rb = false;
alert("Element: " + element.length);
for (i = 0; i < element.length; i++) {
//if (element[i].checked) {
//rb = true;
//}
alert("for loop");
}
// Display a warning message if no option was chosen
if (rb == false) {
var qNum = element.name.substring(9, 8);
alert("Please select an option from Question " + qNum);
//element[0].focus();
return false;
}
}
form.prevElement.value = element.name;
}
The line of code:
alert("Element: " + element.length);
states that element.length is undefined ( this refers to the question elements of the form), but if I put in the elements full name:
form.question1Ans.length
then the correct length is returned.
Any feedback on this would be very much appreciated.
Regards
M