title: jquery validation - submitting form with enter key
body: <p>I am new to javascript and jquery and I'm trying to submit a form which is validated using the jquery validation plugin using the enter key. This is my code but the form is not being submitted as the alert isn't showing when you press enter. I'm not sure what exactly is happening. I think the page is simply being reloaded when i press enter. There's certainly no validation</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function() {
  
          jQuery.validator.setDefaults({
              errorPlacement: function(error, element) {
                   error.appendTo('#invalid_' + element.attr('id'));
  
                    }
          });
  
          var validator = $("#login_form").validate({
              rules: {
                  user_email: {
                    required: true,
                    email: true
  
                  },
                  password: {
                      required: true
                  }
              },
              messages:{
                  user_email:{
                      required:"Email required",
                      email: "Must be a valid email"
                  },
                  password: {
                      required: "Password required"
                  }
  
              }, 
  
  
              submitHandler: function(form) {
              alert('submitted');
                $.ajax({
                  type: "POST",
                  url: "ajax/check_login.php",
                  data: $(form).serialize(),
                  timeout: 3000,
                  success: function(resp) { 
                      if (resp == 'error') {
                          $('#login_error').html('Invalid login');
                      } else {
  
  
                          load_user_area();
  
  
  
  
                      }
  
                  },
                  error: function(e) {alert('failed' + e);}
                });
                return false;
              }
  
          });
  
  
  $(document).keydown(function(e) { 
      if (e.keyCode == 13) { $('#login_form').submit(); }
  });
  
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks in advance for any help!</p>