title: How do I check to make sure form fields are not empty strings?
body: <p>I am trying to get my validateForm() method to make sure email is valid (which I have done) and also make sure the 'name' and 'comments' fields are not empty. For some reason I cannot get the second part down, and need some assistance. Here is the current code I have.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  &lt;!--
  function validateForm() {
      var x = document.forms["myForm"]["email"].value;
      var x = document.forms["myForm"]["name"].value;
      var atpos = x.indexOf("@");
      var dotpos = x.lastIndexOf(".");
      if (atpos &lt; 1 || dotpos &lt; atpos + 2 || dotpos + 2 &gt;= x.length) {
          alert("Not a valid e-mail address");
          return false;
      }
  }
  }
  if (x == null || x == "") {
      alert("Empty Fields");
      return false;
  }
  }
  // --&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>And the form:</p>
  
  <pre><code>&lt;form name="myForm" action="http://webdevfoundations.net/scripts/formdemo.asp" onsubmit="return      validateForm()"  method="POST"&gt;
  Your name: &lt;br&gt;
  &lt;input type="text" name="name" &gt;&lt;br&gt;
  &lt;br&gt;
  Your email: &lt;br&gt;
  &lt;input type="text" name="email"&gt;&lt;br&gt;
  &lt;br&gt;
  Your comments: &lt;br&gt;
  &lt;textarea name="comments" rows="15" cols="50"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>