title: how to form action with javascript
body: <p>I'm trying to insert information from the form to the Database.
  This is the form in html - tried both post and get.</p>
  
  <pre><code>&lt;form id="register" action="script/register.js" method="post"&gt;
  &lt;label for="username"&gt;Username:&lt;/label&gt;
  &lt;input type="text" name="username" id="username" placeholder="Username" /&gt;
  &lt;br&gt;
  &lt;label for="passd"&gt;Password:&lt;/label&gt;
  &lt;input type="password" name="passd" id="passd" placeholder="Password" /&gt;
  &lt;br&gt;
  &lt;label for="conpassd"&gt;Password:&lt;/label&gt;
  &lt;input type ="password" name="conpassd" id="conpassd" placeholder="re-type Password"/&gt;
  &lt;br&gt;
  &lt;label for="email"&gt;E-Mail:&lt;/label&gt;
  &lt;input type="text" name="email" id="email" placeholder="Email address"/&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;button type="submit" name="submitMe" id="submitMe"&gt;Submit&lt;/button&gt;
  &lt;button type="reset"&gt;Clear&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the script</p>
  
  <pre><code>$(document).ready(function() {
      var usernameCorrect = false;
      var passwordCorrect = false;
  
      function checkPassword() {
          var p1 = $("#passd").val();
          var p2 = $("#conpassd").val();
          if(p1 == p2) {
              passwordCorrect = true;
          } else {
              passwordCorrect = false;
              alert("Passwords does not match");
          }
      }
  
      function checkUsername() {
          var user = $("#username").val();
          var dataPass = {
              "username": user
          }
          $.ajax({
              url: "server/userExists.cgi",
              type: "GET",
              dataType: "text",
              data: dataPass,
              success: function(data) {
                  var user = $.trim(data);
                  if(user == "No") {
                      usernameCorrect = true;
                  } else if(user == "Yes") {
                      usernameCorrect = false;
                      alert("Username already in use");
                  }
              },
              error: function() {
                  alert('Script Execution Error');
              },
          });
      }
  
      function submitForm() {
          if(usernameCorrect == true &amp;&amp; passwordCorrect == true) {
              e.preventDefault();
              var dataPass = {
                  'username': (username),
                  'passd': ($("#passd").val()),
                  'email': ($("#conpassd").val())
              };
              $.ajax({
                  url: "server/init.cgi",
                  type: "GET",
                  data: dataPass,
                  success: function() {
                      alert("Register successful");
                      //nextPage(username);
                  },
                  error: function() {
                      alert("Error!");
                  },
              });
          }
      }
  
      $("#submitMe").click(function(e) {
          submitForm();
      });
  
  });
  </code></pre>
  
  <p>Is there anyway to link the form to javascript? I don't know any other language such as php so...
  Thanks</p>