title: How to pass variable from one function to another, both with parameters using JavaScript
body: <p>We have several landing pages with call-to-action buttons ("Download the report", for example) and need to report through a URL string two variables from the actual button click (report title and report type and whether the visitor who is clicking the button is a new or existing client. The analytics company requires the final URL to be sent like this:</p>
  
  <pre><code>https://thisurl.html?assetName=" + assetName + "&amp;assetType=" + assetType + "&amp;custType=" + custType);
  </code></pre>
  
  <p>To gather the assetName and assetType, I've created this function, which has already been in production and works fine for reporting the assetName and assetType.</p>
  
  <pre><code>function tracker(assetName,assetType) {
    var fileref=document.createElement('script');
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", "https://thisurl.html?assetName=" + assetName + "&amp;assetType=" + assetType + "&amp;custType=" + custType);
    if (typeof fileref!="undefined") {        
      document.getElementsByTagName("head")[0].appendChild(fileref);
    }
  </code></pre>
  
  <p>}</p>
  
  <p>Now, we need to also track whether the client is "new" or "current", so I have this function:</p>
  
  <pre><code>function cStatus(elem) {
      var els = [];
      while (elem) {
          els.unshift(elem);
          elem = elem.parentNode;
          if (elem.id == "new") {
              break;
          } else if (elem.id == "current") {
              break;
          }
      }
      custType = elem.id;
  }
  </code></pre>
  
  <p>To clarify, the call-to-action button is included on the page twice, once in the "new" div and the other in the "current" div.</p>
  
  <pre><code>&lt;div id="new"&gt;
  ...button code...
  &lt;/div&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;div id="current"&gt;
  ...button code...
  &lt;/div&gt;
  </code></pre>
  
  <p>In order to create that URL string for reporting, my thinking is to use the "cStatus" function to identify the div id ('new' or 'current'), then use the cStatus function to get the info on the button click. The button has an onclick that passes the 'assetName' and 'assetType':</p>
  
  <pre><code>onclick="tracker('PDF','document.pdf')
  </code></pre>
  
  <p>The problem I'm having is getting all three of those variables into one function, so I can create the URL string for reporting. I've search and found solutions for functions without parameters, but cannot figure out how to pass a variable from one function with parameters "function cStatus(elem)" to another function with parameters "tracker(assetName, assetType), so that it can ultimately be passed along in a URL string for reporting. </p>