title: Can't get JavaScript method to validate my HTML form
body: <p>I'm trying to use a javascript method to validate my form but it doesn't seem to be working. No dialog box pops up warning me of any errors even if an empty form is submitted. What could be the error?
  (Please Note: The JS File has a method defined for a time-stamp that I am currently not using in my form tag. I need some help with calling two functions as well.)</p>
  
  <p>Here's the code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function setDate() {
    document.getElementById('date').value = new Date();
  
  }
  
  function validateForm() {
    var a = document.getElementById('name').value;
    var b = document.getElementById("contact1").value;
    var blen = b.length;
    var c = document.getElementById("address1").value;
    var d = document.getElementById("stblimit").value;
    var dlen = d.length;
    var e = document.getElementById("creditlimit").value;
    var f = document.getElementById("commission").value;
    var g = document.getElementById("servicecharges").value;
    //DATE var h = document.forms["addRetailer"]["date"].value;
  
  
    if (a == null || a == "") {
      alert("Name must be filled out");
      return false;
    } else if (b == null || b == "" || blen == 0 || blen &gt; 10 || blen &lt; 10) {
      alert("Enter a valid number");
      return false;
    } else if (c == null || c == "") {
      alert("Primary Address must be filled out");
      return false;
    } else if (d == null || d == "" || dlen == 0 || dlen &lt; 0) {
      alert("Set Box Top Limit must be filled with a valid number");
      return false;
    } else if (e == null || e == "") {
      alert("Credit Limit must be filled out");
      return false;
    } else if (f == null || f == "") {
      alert("Commission Percentage must be filled out");
      return false;
    } else if (g == null || g == "") {
      alert("Service Charges must be filled out");
      return false;
    }
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
    &lt;script src="formvalidation.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;title&gt;Register Retailer&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;h1&gt;Retailer Information&lt;/h1&gt;
    &lt;form name="addRetailer" action="RetailerController" method="post" onsubmit="return validateForm()"&gt;
  
      &lt;table&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Name&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="name" id="name"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Contact Number 1&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="contact1" id="contact1"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Contact Number 2&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="contact2" id="contact2"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Address Line 1&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="address1" id="address1"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Address Line 2&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="address2" id="address2"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;City&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="city" id="city"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;State&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="state" id="state"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Pin Code&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="pin" id="pin"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Set Top Box Limit&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="stblimit" id="stblimit" value="0"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Credit Limit&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="creditlimit" id="creditlimit"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Commission Percentage&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="commission" id="commission" value="0.0"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Service Charges&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="servicecharges" id="servicecharges"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;Date of Registration&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" name="date" id="date"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
        &lt;tr&gt;
          &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;td&gt;
            &lt;input type="hidden" value="registerCustomer" name="action"&gt;&lt;/input&gt;
            &lt;input type="submit" value="Register"&gt;&lt;/input&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
  
      &lt;/table&gt;
    &lt;/form&gt;
    &lt;br&gt;
    &lt;br&gt;Click
  
    &lt;a href="mainPage.html"&gt; Home &lt;/a&gt;To Return To The Main Screen
  
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <h2>EDIT:</h2>
  
  <p>Here is a screenshot of my Eclipse IDE workspace. My js file and html file aren't in the same sub-folder, although they are under 'Web Content'. Could that be the issue?</p>
  
  <p><a href="http://i.stack.imgur.com/SIZ7i.jpg" rel="nofollow">Screenshot of Eclipse IDE Workspace</a></p>