title: Javascript form validation not running
body: <p>Cant get this form to even run the javascript validation. I have tried changing onclick to onsubmit in the form but havent ever got it to run the script. Sorry if this is an obvious error but ive been searching the internet for a while now. Thanks </p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Email Form Page&lt;/title&gt;
          &lt;link href="mycss.css" rel="stylesheet"&gt;   
          &lt;script type="text/javascript"&gt;
              function validator(){
                  var firstname = document.getElementsById('fname').value;
                  var lastname = document.getElementsById('lname').value;
                  var email = document.getElementsById('email').value;
                  var subject = document.getElementsById('subject').value;
                  var message = document.getElementsById('message').value;
                  var errors = "";
                  regex1 = /^[a-z]+$/;
                  regex2 = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
                  // Checks to see if all fields have been filled in
                  if (firstname == ""){
                      errors += 'First name field is empty \n';
                     }
                  if (lastname == ""){
                      errors += 'Last name field is empty \n';
                     }    
                  if (email == ""){
                      errors += 'Your Email field is empty \n';
                     } 
                  if (subject == ""){
                      errors += 'Subject field is empty \n';
                     }                    
                  if (message == ""){
                      errors += 'Message field is empty \n';
                     }
                  // Checks if first name contains only letters     
                  if (regex1.text(firstname)) == false {
                      errors += 'First name can not contain numbers \n';
                  }
                  // Checks if last name contains only leters 
                  if (regex1.text(lastname)) == false {
                      errors += 'Last name can not contain numbers \n';
                  }   
                  // checks to see if email is valid
                  if (regex2.text(email) == true) {
                      errors += 'Email was not valid \n';
                  }
  
                  //alerts errors and kills form
                  if (errors != ""){
                      alert(errors);
                      return false;
                  }
  
          &lt;/script&gt; 
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;h1&gt; Send me an Email &lt;/h1&gt;
          &lt;div class= "container"&gt;
          &lt;form name="emailform" method="post"&gt;
              First Name: &lt;input type='text' name ='firstname' id="fname"&gt; &lt;br&gt;
              Last Name:  &lt;input type='text' name ='lastname' id="lname"&gt; &lt;br&gt;
              Your Email: &lt;input type='text' name ='email' id ="email"&gt; &lt;br&gt;
              Subject:    &lt;input type='text' name='subject' id ="subject"&gt;  &lt;br&gt;
              Message:    &lt;textarea rows='6' cols='30' name='message' id="messsage"&gt; &lt;/textarea&gt; &lt;br&gt;
              &lt;input type='submit' value ='Send' name='submit' onclick= "validator()"&gt;
          &lt;/form&gt;
          &lt;/div&gt;
      &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>