title: Validating multiple fields in a form
body: <p>I was doing the testing for the first time. I read the <a href="http://www.w3schools.com/js/tryit.asp?filename=tryjs_form_validation" rel="nofollow">this</a> code and made one of my own from it. The thing is that its not giving any error even if the fields are left empty.</p>
  
  <p>Here is my <a href="http://jsfiddle.net/4Nkjq/" rel="nofollow">fiddle</a>.</p>
  
  <p>Please help out. Thanks.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  {function validateForm()
  
  var x=document.forms["myForm"]["name"].value;
  if (x==null || x=="")
    {
    alert("Name must be filled out");
    return false;
    }
  
  var y=document.forms["myForm"]["password"].value;
    {
  if (y==null || y=="")
    alert("Password name must be filled out");
    return false;
    }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post"&gt;
  Name*: &lt;input type="text" name="name"&gt; &lt;br&gt;
  Password*: &lt;input type="password" name="password"&gt;&lt;br&gt;
  Email: &lt;input type="text" name="email"&gt;&lt;br&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>​</p>