title: javascript form submit event doesn't work
body: <p>I have user-registration page and want to sent ajax to another page before register starts.
  I handle form submit event with 'on' but registration doesn't work at now. After submit form just refreshing my page. And send nothing to register module.</p>
  
  <p>Here is my code</p>
  
  <pre><code>function subdomainSent() {
      var subdomain = $('#subdomain').val();
      $.ajax({
          url: '/module/nmo/display',
          type: 'post',
          data: {
              action: 'subdomain_check',
              subdomain: subdomain
          },
          success: function (output) {
              alert(output);
              subdomain_complete();
          }
      });
  }
  
  function subdomain_complete() {
      document.main_form.submit();
  }
  $('#account-creation_form').on('submit', function (e) {
      e.preventDefault();
      subdomainSent();
  });
  if (getUrlParameter("action") == "create_account") {
      $("#account-creation_form").attr("action", "http://" + document.domain + window.location.pathname + "?action=create_account");
      $('#submitAccount').prop('disabled', true);
      $('#subdomain_show').css('display', 'block');
  } else {
      $("#account-creation_form").attr("action", "http://" + document.domain + window.location.pathname);
  }
  </code></pre>
  
  <p>And form</p>
  
  <pre><code>&lt;form name="main_form" action="" method="post" id="account-creation_form" class="std box"&gt;
  </code></pre>
  
  <p><strong>Update:</strong>
  used solution by @Branimir Đurek and
  improved my code like this </p>
  
  <pre><code>if(start)
  {
      var subdomain = $('#subdomain').val();
          $.ajax({
              url: '/module/nmo/display',
              type: 'post',
              data: {action: 'subdomain_check', subdomain: subdomain},
              success: function(output) {
                  start = false;
              }
          });
  }
  else if(!start)
  {
      subdomain_complete();
  }
  </code></pre>
  
  <p>and all works at now.</p>