title: SweetAlert with Java Servlet
body: <p>I wanted to pause form's onsubmit, so I could ask user to confirm action before proceed.
  So here's my form:</p>
  
  <pre><code>            &lt;form action="&lt;%= request.getContextPath()%&gt;/Controller" 
                    method="POST" id="remove_book" 
                    onsubmit="alertBookInfo('return_book')"&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>Then, I created the JavaScript function, using SweetAlert:</p>
  
  <pre><code>function alertInfo(action) {
  document.querySelector(action).addEventListener('submit', function (e) {
      var form = this;
      e.preventDefault();
      if (action === "remove_book") {
          swal({
              title: "Remove book?",
              text: "Watch out",
              type: "warning",
              showCancelButton: true,
              confirmButtonColor: "#DD6B55",
              confirmButtonText: "Yes.",
              cancelButtonText: "No.",
              closeOnConfirm: false,
              closeOnCancel: false
          },
          function (isConfirm) {
              if (isConfirm) {
                  swal({
                      title: "Deleted.",
                      text: "Done.",
                      type: "success"
                  }, function () {
                              form.submit();
                  });
              } else {
                  swal("Cancelled", "Not done.", "error");
              }
          });
      }
  });
  }
  </code></pre>
  
  <p>But for some reason, I am unable to prevent page reload on form submit. Am I doing someting wrong? </p>
  
  <p>PS: I already tried with return alertInfo() in form and returning boolean value from JS function with no success.</p>