title: JavaScript Form Validation
body: <p>I'm trying to create a form submission and before the form is submitted, I want to verify the credentials.</p>
  
  <p>I have both this so far</p>
  
  <p>HTML formatted for XHTML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  
      &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
          &lt;head&gt;
              &lt;title&gt; Registration Form&lt;/title&gt;
              &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt;
              &lt;meta name="description" content="This is a form submission with validation"/&gt;
              &lt;script type="text/javascript" src="validScript.js"&gt;&lt;/script&gt;
          &lt;/head&gt;
  
          &lt;body&gt;
              &lt;h1&gt;Registration Form&lt;/h1&gt;
              &lt;form id="registration" action="" onsubmit="return validation();" method="post" enctype="text/plain"&gt;
                  &lt;p&gt;Name: &lt;input type="text" name="name" id="name"/&gt;&lt;/p&gt;
                  &lt;p class="error"&gt;Email Address: &lt;input type="text" name="emailAddress" id="emailAddress"/&gt;&lt;/p&gt;
                  &lt;p&gt;&lt;input type="submit" name="submit" value="Submit"/&gt;&lt;/p&gt;
              &lt;/form&gt;
          &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code> function validation()
  {  
      var vname = document.registration.name;
  
      if(nameValid(vname))
      {
          return true;
      }
      return false;
  }
  
  function nameValid(vname)
  {
      var name_len = vname.value.length;
      if (name_len == 0)
      {
          alert("Name is required");
          vname.focus();
          return false;
      }
  return true;
  }
  </code></pre>
  
  <p>I'm having issues where it won't display alert the user that he/she prompted an empty name. I'm trying to valid the name and after this I'll add more functions for email address and other fields to be added. Note that this will later be used to email the form to a domain. Can someone help me figure out this problem?</p>
  
  <p>Thanks</p>