title: Pass google script value to html
body: <p>I have been looking at various other solutions posted here but none of them seem to work for me. </p>
  
  <p>I'm trying to pass a variable from my google script (which is originally stored in google's PropertiesService) to my html, because I want to use previously saved data as values for my text input box (showing the previously saved data).</p>
  
  <p>This is my gs file (minus unrelated parts):</p>
  
  <pre><code>function openSettings() {
  
    var htmlTemplate = HtmlService.createTemplateFromFile('settingsForm')
  
  
    var userProperties = PropertiesService.getUserProperties();
    var time = userProperties.getProperty('selectedTime');
    htmlTemplate.timehtml = time;
  
    var html = htmlTemplate.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('Settings')
      .setWidth(300)
    SpreadsheetApp.getUi()
      .showSidebar(html);
    return html
  }
  
  function processForm(form) {
  
    var userProperties = PropertiesService.getUserProperties();
  
    var time = userProperties.getProperty('selectedTime');
    time = form.time;
    userProperties.setProperty('selectedTime', time);
  }
  </code></pre>
  
  <p>And this is my html file (left out other unrelated parts):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  
  &lt;div&gt;
   &lt;form&gt;
     &lt;input type="text" name="time" id="time" style="width: 40px;"&gt;
     &lt;br&gt;&lt;br&gt;&lt;input type="button" class="action" onClick="writeFormData(); 
     alert('submitted')" value="Submit"/&gt;
   &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
    var timeInput = document.getElementById("time");
    var timehtml = time;
    timeInput.value = timehtml;
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
         function writeFormData() {
             google.script.run.processForm(document.forms[0]);
         }
  &lt;/script&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Perhaps my whole approach is wrong. But what I'm trying to do is store the user choices (might want to change userProperties to documentProperties, to make the settings document specific) in Google's PropertiesService and then save these values when the submit buttons is pressed in a sidebar. Next time when the sidebar is opened these saved settings should be shown.</p>