title: Javascript - How do I prevent functions from running multiple times, incrementally, after each button click?
body: <p>I am flabbergasted trying to figure out a way to prevent the button click from rendering multiple times based on the number of clicks. If you I click &quot;submitButton&quot; once, everything runs once. If I click it a second time, everything runs twice. If I click it a third time, everything runs three times... And so on...</p>
  <p>Here is the code I am running to initiate the running of several functions. The subsequent functions grab data from a database, creates batches of 100, then inserts that data into an HTTP POST request.</p>
  <pre><code>      submitButton.addEventListener(&quot;click&quot;, () =&gt; {
          if (document.getElementById(&quot;subject&quot;).value == &quot;&quot;) {
            alert(
              &quot;Please add a Subject for your Push Notification before sending.&quot;
            );
          } else if (document.getElementById(&quot;body&quot;).value == &quot;&quot;) {
            alert(
              &quot;Please add a Message Body for your Push Notification before sending.&quot;
            );
          } else if (
            document.querySelectorAll(&quot;input[type=radio]:checked&quot;).length &lt; 1
          ) {
            alert(&quot;Please select a Jump-To page before sending.&quot;);
          } else {
            btn.classList.add(&quot;button--loading&quot;);
            submitButton.disabled = true;
            SelectData();
          }
        });
  </code></pre>
  <p>Following <code>SelectData();</code> are the functions that batch, create and send the HTTP POST request. At the end of all of this, I've attempted to add the following to prevent some type of storage of EACH click event, operating under the assumption that is my problem. That is, that each click is being stored locally in the browser, and thus if number of clicks = 2 then <code>SelectData();</code> will run twice along with all other functions related to the click event.</p>
  <pre><code>            submitButton.removeEventListener(&quot;click&quot;, null);
              submitButton.disabled = false;
  </code></pre>
  <p>I was hopeful the above would be my answer, but it has not done anything differently. I'd love some help and am happy to provide more specifics if necessary, but i am stumped. I appreciate your help in pointing me in the right direction!</p>