Hi Paul,

ok, so, FieldList is a string (comma sepearated) of those fields you want to
check and depending on the type of field you are then checking to see, in
this case, whether the radio button is checked.

Firstly, why is it important that you know how many readio buttons there are
of the name WorkStatus?


The reason why "theForm.elements[i].length" doesn't work, is because there
is no length property for that form object. The fact it works if you use the
name, is probably some special feature built into IE (or a new JavaScript
feature) for a quicker way of counting the elements with the same name.

But why is it necessary you know this 'count' using the index?


Cheers,
Nick



:> -----Original Message-----
:> Hi,
:>
:> Heres the code, its called by passing is a list of fields to check for,
:> idea being that it'll be called and the fields can be passed dynamically.
:>
:> Theres a few alerts used for debugging
:>
:> var theForm = document.forms.ClaimForm;
:>
:> function CheckForm(FieldList)
:> {
:>      var error = false;
:>
:>      //this works if we use the full name off the form element
:> rather than the
:> element array id ie i in the for loop
:>      alert("this many radios " + theForm.elements["WorkStatus"].length)
:>
:>      for (var i=0; i < theForm.elements.length; i++)
:>      {
:>              //see if the form element we are on is one that we
:> want to check -
:> passed in FieldList
:>              if (FieldList.indexOf(theForm.elements[i].name) != -1)
:>              {
:>                      //we've found a field that we want to check
:>
:>                      //now we need to detect its type and
:> process it accordingly
:>                      switch (theForm.elements[i].type)
:>                      {
:>
:>                              case "radio":
:>                                      //WHY DOESN"T THIS WORK!!????
:>                                      //alert(theForm.elements[i].length);
:>                                      alert(i);
:>                                      if
:> (theForm.elements[i].checked == false)
:>                                      {
:>                                              error = true;
:>
:> alert(theForm.elements[i].name);
:>                                      }
:>                                      break;
:>                              case "text":
:>                                      if (theForm.elements[i].value == '')
:>                                      {
:>                                              error = true;
:>
:> alert(theForm.elements[i].name);
:>                                      }
:>                                      break;
:>                              case "checkbox":
:>                                      if
:> (theForm.elements[i].checked == false)
:>                                      {
:>                                              error = true;
:>
:> alert(theForm.elements[i].name);
:>                                      }
:>                                      break;
:>                              case "select-one":
:>                                      if (theForm.elements[i].value == '')
:>                                      {
:>                                              error = true;
:>
:> alert(theForm.elements[i].name);
:>                                      }
:>                                      break;
:>                      }
:>              }
:>
:>      }
:>
:>      alert(error);
:>
:> }
:>
:> Paul Broomfield
:>
:> ---
:> You are currently subscribed to activeserverpages as:
:> [EMAIL PROTECTED]
:> To unsubscribe send a blank email to
:> %%email.unsub%%
:>


---
You are currently subscribed to activeserverpages as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to