title: Javascript Form Validation- can't validate one variable?
body: <p>I made a contact form for my website and I want to make validations. This is the HTML:</p>
  
  <pre><code>&lt;form name="contact" method="post" action="Contact.php" onsubmit="return validateForm()" &gt;
              &lt;span class="formtext"&gt; name:&lt;/span&gt; &lt;input id="nameinput" type="text" name="name" /&gt;&lt;br /&gt;
              &lt;span class="formtext"&gt; email:&lt;/span&gt; &lt;input id="mailinput" type="text" name="email" /&gt;&lt;br /&gt;
              &lt;span class="formtext"&gt; message:&lt;/span&gt;&lt;br  /&gt; &lt;textarea id="messageinput" type="text" name="message"&gt; &lt;/textarea&gt; &lt;br /&gt;
              &lt;input id="submitinput" name="submit" type="submit" value="שלח"/&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>This is the JS:</p>
  
  <pre><code>// Contact Form //
  function validateForm()
  {
  var x=document.forms["contact"]["name"].value;
  var y=document.forms["contact"]["email"].value;
  var atpos=y.indexOf("@");
  var dotpos=y.lastIndexOf(".");
  var z=document.forms["contact"]["email"].value;
  if (x==null || x=="" || y==null || y=="" || z=="" || z==null)
    {
    alert("Please fill all the details");
    return false;
    }
    else
    if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=y.length)
    {
    alert ("Please fill a valid email address");
    return false;
    }
  }
  </code></pre>
  
  <p>The problem has something to do with the variable 'z'. When I fill the form and send it, I get the "Please fill all the details" alert, even though I did fill the textarea. I know it's the 'z' because if I remove both the variable and the part inside the 'if' that has something to do with var 'z', the problem is solved- but then there is no validation.</p>