title: Integrate the results of one javascript function into another
body: <p>I have been having trouble integrating both these scripts in to my HTML page. </p>
  
  <p>Firstly, I have one javascript that compiles the results of dropdown boxes and text boxes into a string text. That works fine.</p>
  
  <p>The second javascript creates a txt file that can be downloaded (in a multiline array). What I am trying to do is get the results of the string made in <code>function generate()</code> to appear as a single line in the array of javascript download command... </p>
  
  <p>FYI - I have all this in one html file since its light weight...</p>
  
  <p>Thanks in advance for your help!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function generate(){
      var result = '';
  
      result += document.getElementById('drop1').value + ' - ';
      result += document.getElementById('drop2').value + ' - ';
      result += document.getElementById('drop3').value + ' - ';
      result += document.getElementById('text1').value + ' - ';
      result += document.getElementById('text2').value;
  
   document.getElementById('output').innerHTML = result;
  }
  generate();
  
  function download(filename, text) {
    var element = document.createElement('a');
    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    element.setAttribute('download', filename);
    element.style.display = 'none';
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);
  }
  
  function getLastUpdated() {
    return result;
  }
  
  // Start file download.
  document.getElementById("dwn-btn").addEventListener('click', function(){
    // Generate download of hello.txt file with some content
    var text = [
      'A rather long string of English text, an error message',
      getLastUpdated(),
      'end'
    ].join('\n');
  
    var filename = "hello.txt";
  
    download(filename, text.replace(/\n/g, '\r\n')); // Convert LF ro CRLF
  }, false);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;select id="drop1" onchange="generate()"&gt;
      &lt;option value="d1s1"&gt;D1 S1&lt;/option&gt;
      &lt;option value="d1s2"&gt;D1 S2&lt;/option&gt;
  &lt;/select&gt;
  &lt;select id="drop2" onchange="generate()"&gt;
      &lt;option value="d2s1"&gt;D2 S1&lt;/option&gt;
      &lt;option value="d2s2"&gt;D2 S2&lt;/option&gt;
  &lt;/select&gt;
  &lt;select id="drop3" onchange="generate()"&gt;
      &lt;option value="d3s1"&gt;D3 S1&lt;/option&gt;
      &lt;option value="d3s2"&gt;D3 S2&lt;/option&gt;
  &lt;/select&gt;
  &lt;input id="text1" type="text" value="text1" onchange="generate()" onkeyup="generate()" /&gt;
  &lt;input id="text2" type="text" value="text2" onchange="generate()" onkeyup="generate()" /&gt;
  
  &lt;p id="output"&gt;&lt;/p&gt;
  
  &lt;input type="button" id="dwn-btn" value="Download" /&gt;</code></pre>
  </div>
  </div>
  </p>