title: bootstrap 4 call javascript function on form validation
body: <p>So I'm using Bootstrap 4 for my project, and I really like the way their validation works for each input element in a form. I'm using this code to validate my form, this was off their website:</p>
  
  <pre><code>&lt;script&gt;
      (function () {
          "use strict";
          window.addEventListener(
              "load",
              function () {
                  // Fetch all the forms we want to apply custom Bootstrap validation styles to
                  var forms = document.getElementsByClassName("needs-validation");
                  // Loop over them and prevent submission
                  var validation = Array.prototype.filter.call(forms, function (form) {
                      form.addEventListener(
                          "submit",
                          function (event) {
                              if (form.checkValidity() === false) {
                                  event.preventDefault();
                                  event.stopPropagation();
                              }
                              form.classList.add("was-validated");
                          },
                          false
                      );
                  });
              },
              false
          );
      })();
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The only thing is, in my javascript file, I have another listener that's supposed to get fired when the sign-up button is submitted inside my form. For whatever reason, even once all the input fields are validated, I can't get it to call my submit function. Here's the code inside my javascript file:</p>
  
  <pre><code>document.addEventListener("DOMContentLoaded", function() {
     initApp();
  });
  
  
  function initApp() {
      document.querySelector("#sign-up").addEventListener("submit", createAccount, false);
  }
  
  function createAccount() {
      alert('test');
  }
  </code></pre>
  
  <p>I've tried a bunch of stuff like moving this validation code before and after the initialization of my js file, but nothing worked. The goal is to have 2 submit buttons in this form (one is sign up, other is log in) and depending which one is pressed, a different function should be called. If anyone has any ideas, I'd appreciate it!</p>