title: Javascript text field validation
body: <p>I am having difficulty validating a form in javascript. I'm currently checking just a text field and it doesn't work. My code is as followed: </p>
  
  <p>index.html:</p>
  
  <pre><code>&lt;html xmlns = "http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt; 
      &lt;title&gt;
          Validation Form
      &lt;/title&gt;
      &lt;script type = "text/javascript" src ="vForm.js"&gt;
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id = "myForm" action =""&gt;
          First name: &lt;input type="text" name="fname"&gt;&lt;/br&gt;
          Last name: &lt;input type="text" name="lname"&gt;&lt;/br&gt;
          Password: &lt;input type="password" name="pass1"&gt;&lt;/br&gt;
          Re-enter password: &lt;input type="password" name="pass2"&gt;&lt;/br&gt;
          Email: &lt;input type="text" name="email"&gt;&lt;/br&gt;
          Phone: &lt;input type="text" name="phone"&gt;&lt;/br&gt;
          Address: &lt;input type="text" name="add"&gt;&lt;/br&gt;
          Date: &lt;input type="date" name="date"&gt;&lt;/br&gt;
          Time: &lt;input type="time" name="time"&gt;&lt;/br&gt;
          &lt;input type="reset" name="reset"&gt;
          &lt;input type="submit" name="submit"&gt;
      &lt;/form&gt;
      &lt;script type = "text/javascript" src ="vFormRun.js"&gt;
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>vForm.js:</p>
  
  <pre><code>function validateForm()
  {
      var fname = document.getElementById("fname");
      var lname = document.getElementById("lname");
      var pass1 = document.getElementById("pass1");
      var pass2 = document.getElementById("pass2");
      var email = document.getElementById("email");
  
      if(fname == "")
      {
          alert("Please enter first name")
          return false;
      }
      else
      {
          return true;
      }
  }
  </code></pre>
  
  <p>vFormRun.js:</p>
  
  <pre><code>document.getElementById("myForm").onsubmit = validateForm;
  </code></pre>