title: Calling javascript validation function before submiting and calling servlet
body: <p>I am trying to validate the form and after that calling a servlet and it fails because form doesn't validete. I' ve pasted some code below. Could you give me some tips and help with this issue?</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 validateForm()
  {
      if(document.frm.username.value=="")
      {
        alert("User Name can not be left blank");
        document.frm.username.focus();
        return false;
      }
      else if(document.frm.pwd.value=="")
      {
        alert("Password can not be left blank");
        document.frm.password.focus();
        return false;
      }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;link href="/LoginExample/css/style.css" rel="stylesheet" type="text/css" /&gt;
  &lt;script language="JavaScript" type="text/JavaScript" src="/LoginExample/js/validation.js"&gt;&lt;/script&gt;
  &lt;title&gt;Login example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="loginform" action="login" method="post" onSubmit="return validateForm();"&gt;
  &lt;p&gt; Enter user name: &lt;input type="text" name="username"&gt;&lt;br&gt;
  Enter password: &lt;input name="password" type="password"&gt;&lt;br&gt; 
  &lt;input type="submit"&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  
  &lt;a href="register.jsp"&gt;&lt;input type="button" value="register" name="Sign in"&gt;&lt;/a&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>