title: Submitting form with ajax and reloading location to current tab
body: <p>I have a web page with a few different tabs, some with forms. On successful submission of any form, I am reloading the page, but it keeps going to the default first tab. I am trying to set a storage variable to help toggle if it is the first time loading the page (open the default tab) or is being reloaded via form submission (pass that tab's id as variable and load it on reload)</p>
  
  <p>How can I successfully reload on a specific tab?</p>
  
  <p>Below is the form submission function with ajax I am calling</p>
  
  <pre><code>    //submit all forms on page
      const submitForm = (formID, targetTab) =&gt; {
          let theForm = document.getElementById(formID);
  
          //function will determine whichform is being passed and send data to PHP page
          //on reload trying to detect current tab and load to that location
          $.ajax({
              type: 'POST',
              url: $(theForm).attr("action"),
              data: $(theForm).serialize(),
              success: function (response) {
                  location.reload()
                  initFunction(targetTab)
              }
          });
      }
  </code></pre>
  
  <p>This is the function handling which tab to reload, I call it initially on pageload, is that where the problem is?</p>
  
  <pre><code>   const initFunction = (tab) =&gt; {
          let reloading = sessionStorage.getItem("reloading");
          if (!reloading) {
              document.getElementById(tab).click();
              sessionStorage.setItem("reloading", 'true');
          } else {
              document.getElementById(tab).click();
          }
      };
  
      //clicks on default first tab
      window.onload = initFunction('defaultOpen');
  </code></pre>
  
  <p>Here is an example of my nav tab buttons and a one of the form submission buttons</p>
  
  <pre><code>//nav
      &lt;li class="nav-item"&gt;
          &lt;a class="nav-link bg-primary tabLink text-white" href="#" id="defaultOpen" 
           onclick="changeTab(event, 'companytab')"&gt;
          &lt;i class="fa fa-building"&gt;&lt;/i&gt;&amp;nbsp;Company&lt;/a&gt;
       &lt;/li&gt;
  
     &lt;li class="nav-item "&gt;
        &lt;a class="nav-link bg-primary tabLink text-white" href="#"
            onclick="changeTab(event, 'contacttab')" id="contacttabbtn"&gt;
            &lt;i class="fa fa-user"&gt;&lt;/i&gt;&amp;nbsp;Contacts&lt;/a&gt;
    &lt;/li&gt;
  
  //button 
     &lt;button onclick="submitForm('updateProspect', 'defaultOpen')"
                id="saveBtn"class="float-right d-none btn btn-sm btn-success"&gt;&lt;i class="fa fa-save"&gt; 
                &lt;/i&gt;&amp;nbsp;Save
     &lt;/button&gt;
  
  </code></pre>
  
  <p>Thanks!</p>