title: Why does calling this Javascript function submit my form?
body: <p>I have a form validation script. Unless all conditions are met, the ambiguous function associated with <code>form.onclick</code> returns false (form doesn't submit). I have another function which upon error will append an error message to the errorLog div.</p>
  
  <pre><code>  function addError (msg) {
      msg = document.createTextNode(msg);
      br = document.createElement("br");
      errorLog.append(msg);
      errorLog.append(br);
      alert("yes");
    }
  </code></pre>
  
  <p>If an error is found, calling this function submits the form. The script doesnt even enter the function, it simply submits the data and refreshes. I realize there is an error in the function, but i cant seem to figure it out.</p>
  
  <p>edit: more of my code </p>
  
  <pre><code>  form.onsubmit = function () 
    {
      if (nameCheck(fname, lname))
        return true;
  
      return false; 
    };
  </code></pre>
  
  <p>function that checks if "name" field is valid:</p>
  
  <pre><code>function nameCheck (fname,lname)
  {
    if (("/\d/").test(fname) || ("/\d/").test(lname))
    {
      addError('Your name cannot contain numbers.');
      valid = false;
    }
  }
  </code></pre>