title: Loading form input fields into a javascript array and then validating
body: <p>I seem to be really stuck on something. I have a function to check if all the form input fields are equal to null or "" which is all fine but wanted to see if there is another way of doing it by loading all the fields into a javascript array and then doing a for loop along with an if statement to check if any of the fields are empty, unfortunately I can't seem to get this to work and wondering if I've simply just missed something some where. Here is my code:</p>
  
  <pre><code>function checkempty()
  {
      fname = document.getElementById("firstname").value;
      lname = document.getElementById("lastname").value;
      fage = document.getElementById("age").value;
      addressl1 = document.getElementById("addressline1").value;
      addressl2 = document.getElementById("addressline2").value;
      ftown = document.getElementById("town").value;
      fcounty = document.getElementById("county").value;
      fpcode1 = document.getElementById("pcode1").value;
      fpcode2 = document.getElementById("pcode2").value;
      ftelephone = document.getElementById("telephone").value;
      fcomment = document.getElementById("comment").value;
  
      var myArray = [];
      myArray[0] = fname;
      myArray[1] = lname;
      myArray[2] = fage;
      myArray[3] = addressl1;
      myArray[4] = addressl2;
      myArray[5] = ftown;
      myArray[6] = fcounty;
      myArray[7] = fpcode1;
      myArray[8] = fpcode2;
      myArray[9] = ftelephone;
      myArray[10] = fcomment;
  
      for(i=0;i&lt;myArray.length;i++)
      {
          if(!myArray[0])
          {
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>I then use another function:</p>
  
  <pre><code>function checkform()
  {
    if(checkempty)
    {
       display_errormessage("One or more fields empty!");
    }
    else
    {
       alert("Thanks for you input!");
    }
   }
  </code></pre>
  
  <p>The display_errormessage() function is just one that puts an error message into a div at the top of the form to display an error message if the form is incomplete.</p>
  
  <p>Can anyone see where i've gone wrong?</p>
  
  <p>Thanks in advance for any help!</p>
  
  <p>Dave.</p>