title: Pass Google Script Array to Javascript Function (Google Apps)
body: <p>I understand why my code does not work, however I can't find a solution searching online. Likely a simple syntax correction. Here is the code:</p>
  
  <h2>Code.gs</h2>
  
  <pre><code>function doGet() {
    return HtmlService
     .createTemplateFromFile('Index')
    .evaluate()
    .setSandboxMode(HtmlService.SandboxMode.IFRAME);
   }
  
   function getData() {
     return SpreadsheetApp
    .openById('My Sheet ID')
    .getActiveSheet()
    .getDataRange()
    .getValues();
   }
  </code></pre>
  
  <h2>Index.html</h2>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;base target="_top"&gt;
      &lt;style&gt;
      h1 {
      width: 100%;
      overflow: hidden;
      background-color: #ABC;
      }
      #wrapper { 
      margin: auto;
      width: 60%;
      border: 3px solid #000;
      padding: 10px;
      }
  
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;div id="wrapper"&gt;
    &lt;h1&gt;Attendace Discrepancy Tracker v1.0&lt;/h1&gt;
  
    &lt;h3&gt;Discrepancy date:&lt;/h3&gt;&lt;input type="date" name="bday" min="2000-01-02"&gt;&lt;br&gt;
  
      &lt;? var data = getData(); ?&gt; &lt;------ Gets data from my sheet
  
      &lt;h3&gt;Select a name:&lt;/h3&gt;&lt;select id='empName' onchange="findEmpID();"&gt;
        &lt;? for (var i = 1; i &lt; data.length; i++) { ?&gt;
              &lt;option value="&lt;?= i ?&gt;"&gt;&lt;?= data[i][2] + ", " + data[i][1] + " " + data[i][3]?&gt;&lt;/option&gt;
        &lt;? } ?&gt;
  
      &lt;/select&gt;
  
      &lt;div id="empProfile"&gt;
        &lt;p&gt;Employee Number: &lt;span id="empNumber"&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;Supervisor: &lt;span id="empSup"&gt;&lt;/span&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;/div&gt;
      &lt;script&gt;
        function findEmpID () {
          var e = document.getElementById("empName");
          var strUser = e.options[e.selectedIndex].value;
          document.getElementById("empNumber")
          .innerHTML = &lt;?= data[strUser][0] ?&gt;; &lt;----- This does not work
        }
  
  &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The whole program works, except when I try and reference back to the <code>data</code> array. I need a way to pass the <code>&lt;script&gt;</code> tags <code>strUser</code> value to the <code>data</code> array google script variable so I can get the supervisors ID number. Obviously when I switch to the <code>&lt;?</code> tag space it cannot read variables from the <code>&lt;script&gt;</code> tag. I am sure it is possible, just have not figured out how.</p>