title: Form validation issue in HTML
body: <p>People, I am having a problem in my HTML form validation. Currently I am using JSP (at the back end) to extract the form data and jquery to validate the data in my HTML file. Problem is that when i run my HTML on server (apache tomcat), my jquery validation snippet doesn't work and data simply gets passed to the JSP file. Only if I remove the <strong>action</strong> attribute from <strong>form</strong> tag then the validation code runs but JSP doesn't get called. Here are my HTML and JSP scripts.</p>
  
  <pre><code>    &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
             &lt;%@ page import="java.io.*,java.util.*,javax.mail.*"%&gt;
             &lt;%@ page import="javax.mail.internet.*,javax.activation.*"%&gt;
             &lt;%@ page import="javax.servlet.http.*,javax.servlet.*" %&gt;
             &lt;%@ page import =    "java.util.regex.Pattern,java.util.regex.Matcher,java.util.regex.*" %&gt;
  
  
             &lt;!DOCTYPE html&gt;
             &lt;html&gt;
             &lt;head&gt;
             &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
             &lt;title&gt;Yay!&lt;/title&gt;
             &lt;/head&gt;
             &lt;body&gt;
  
  
             &lt;%
  
              //--------------&gt;
              String first = request.getParameter("firstname");
              String last = request.getParameter("lastname");
              String Username = request.getParameter("username");
              String Email = request.getParameter("email");
              String day = request.getParameter("date");
              String month = request.getParameter("month");
              String year = request.getParameter("year");
              String pass1 = request.getParameter("password"); 
              String pass2 = request.getParameter("confirmpassword"); 
              String date = day + '/'+ month + '/' + year ;
  
  
             %&gt;
  
             &lt;%= first %&gt;&lt;br&gt;
             &lt;%= last %&gt;&lt;br&gt;
             &lt;%= Username %&gt; &lt;br&gt;
             &lt;%=  Email%&gt; &lt;br&gt;
             &lt;%=  date%&gt; &lt;br&gt;
             &lt;%=  pass1%&gt; &lt;br&gt;
             &lt;%=  pass2%&gt; &lt;br&gt;
  
  
             &lt;/body&gt;
             &lt;/html&gt;
             &lt;!-- HTML file--&gt;
             &lt;form class = ".form-inline"  
             method = "POST" action =       "process.jsp"
  
                          onSubmit="return validate(this);" name="form"  &gt;
                              &lt;lable&gt;&lt;b&gt;Name:&lt;/b&gt;&lt;/lable&gt;
  
                              &lt;input type = "text" placeholder = "first" 
                           id =   "firstname" 
                              name = "firstname"&gt;&lt;/input&gt;
                              &lt;input type = "text" placeholder = "last" 
                            id = "lastname"
                              name = "lastname"&gt;&lt;/input&gt;&lt;br&gt;&lt;br&gt;
  
                              &lt;label&gt;Birthday:&lt;/label&gt;
                              &lt;div class = "date"&gt;
                                  &lt;input type = "text" placeholder = "dd" 
                              id =  "date" name = "date"&gt;&lt;/input&gt;
                                  &lt;input type = "text" placeholder = "mm" 
                              id = "month" name = "month"&gt;&lt;/input&gt;
                                  &lt;input type = "text" placeholder = "yy" 
                              id = "year" name="year"&gt;&lt;/input&gt;
                                  &lt;br&gt;&lt;br&gt;
                              &lt;/div&gt;
  
  
                                  &lt;div class="form-group "&gt;
  
                                  &lt;label&gt;&lt;b&gt;User Name:&lt;/b&gt;&lt;/label&gt;
                                  &lt;input type = "text"
                                  class = "form-control"  
                                  id = "username"  name="username"&gt;&lt;/input&gt;
                                  &lt;br&gt;
  
                                  &lt;label for="password"&gt;Password:&lt;/label&gt;
                                  &lt;input type="password"
                                  class="form-control"  
                                  id="password" name = "password"&gt;
                                  &lt;br&gt;
  
                                  &lt;label for="confirmpassword"&gt;
                                  Confirm Password:&lt;/label&gt;
                                  &lt;input type="password" 
                                  class="form-control" 
                                  id="confirmpassword" name = "confirmpassword"&gt;
                                  &lt;label for="email"&gt;Email:&lt;/label&gt;
                                  &lt;input type="email" 
                                  class="form-control" id="email" name ="email"&gt;
                                  &lt;br&gt; 
  
                                  &lt;button type="submit" 
                                  class="btn btn-primary btn-block" 
                                  id = "submission"
                                  value ="submit"&gt;Submit&lt;/button&gt;
                                  &lt;script type="text/javascript"&gt;
                                  /*global $*/
                                  $(function(){ // JS form validation snippet.
  
                                          // variables are used to
                                          store  different types of
                                          regex expressions. 
                                          var ck_name = /^[A-Za-z0-9 ]{3,20}$/;
  
  var ck_email
                         = /^([\w-]+ (?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]   {0,66})
                          \.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
                                          var ck_username = 
                                          /^[A-Za-z0-9_] {1,20}$/;
                                          var ck_password =  
                                          /^[A-Za-z0-9!@#$%^&amp;*()_]{6,20}$/;
                                          var flag;
                                          $("#submission").on("click", 
                                          function validate(form){
                                              var day = $("#date").val();
                                              var month = $("#month").val();
                                              var year = $("#year").val();
                                              if ((day &gt;= 1 &amp;&amp; day &lt;= 31 ) &amp;&amp; 
  
                                                (month &gt;= 1 &amp;&amp; month &lt;= 12) &amp;&amp; 
                                                  (year &gt;= 1930)) {
  
                                                      //alert("correct date ");
                                                  }
                                              else {
                                                  //alert("wrong date"); 
                                              }
                                              //alert("submission active");
  
                         // variable extracts 
                            the  specific  user input from the form. 
  
                                        var firstname = $("#firstname").val(); 
                                        var lastname = $("#lastname").val(); 
                                        var email = $("#email").val(); 
                                        var username = $("#username").val(); 
  
                                        var password = $("#password").val(); 
  
                             var confirmpassword = $("#confirmpassword").val(); 
  
                                              var errors = [];
  
                                              if (!ck_name.test(firstname)) {
                           errors[errors.length] = "Your valid first Name .";
                                               }
                                                if (!ck_name.test(lastname)) {
                            errors[errors.length] = "Your valid last Name .";
                                               }
                                               if (!ck_email.test(email)) {
                            errors[errors.length] = 
                               "Yor must enter a valid email address.";
                                               }
  
                               if(!ck_username.test(username)) {
                                               errors[errors.length] = 
  
                                       "Your valid UserName no special  char .";
                                               }
                                               if  (!ck_password.test(password) )                                 {
                                       errors[errors.length] = 
                                       "Your must enter a valid Password ";
                                               }
  
                               if  (!ck_password.test(confirmpassword) ||
                                               password !== confirmpassword) {
                              errors[errors.length] = "password doesn't match ";
                                               }
                                               if (errors.length &gt; 0) {
                                                reportErrors(errors);
                                                return false;
                                               }
  
                //$.get("process.jsp", [firstname, lastname, email, username,
                               password, confirmpassword, day, month, year]);
                                                  //alert(".get() executed");
                                                return true;
  
                                              function reportErrors(errors){
  
                                    var msg = "Please Enter Valide Data...\n";
  
                                   for (var i = 0; i&lt;errors.length; i++) {
                                                   var numError = i + 1;
  
                                   msg += "\n" + numError + ". " + errors[i];
                                              }
                                               //alert(msg);
                                          }
                                      });
                                  });
                                  &lt;/script&gt;
                              &lt;/div&gt;
                      &lt;/form&gt;
  </code></pre>