Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The project trigger <code>onFormSubmit()</code> will be triggered by a submission via the <a href="https://developers.google.com/apps-script/reference/forms/" rel="nofollow noreferrer">Forms Service</a>. There is no relationship between this trigger and your HTML code; they are two different ways to interact with users.</p> <p>An html forms pattern is shown in the HTML Service documentation <a href="https://developers.google.com/apps-script/guides/html-service-communication#forms" rel="nofollow noreferrer">here</a>, and the script below is an adaptation of it.</p> <h3>Code.gs</h3> <p>The only real change from your original is that <code>onFormSubmit()</code> has been replaced with <code>processForm(form)</code>, which includes a parameter, for the object that will be passed from the html code.</p> <pre><code>function onOpen() { var sheet = SpreadsheetApp.getActiveSpreadsheet(); var entries = [{ name : "htmltest", functionName : "htmltest" }]; sheet.addMenu("Custom Menu", entries); }; function htmltest(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var sht = ss.getActiveSheet(); var html = HtmlService.createTemplateFromFile("HTML"); html.fname = sht.getRange(2, 3).getValue(); //Logger.log( html.getCodeWithComments() ); ss.show(html.evaluate()); }; function processForm(form){ var fname = form.fname; Browser.msgBox("Test - " + fname); }; </code></pre> <h3>HTML.html</h3> <p>This is a modification of your original, echoing the pattern from the documentation. The form submission SuccessHandler is a one-liner, which closes the dialog. Once it completes, the server-side function is invoked with the form content, retrieved using <code>this.parentNode</code> (to refer to the form).</p> <p>There are other ways - see <a href="https://stackoverflow.com/questions/16525553/get-value-of-html-text-box-in-apps-script-function">Get value of html text box in Apps Script function</a> for a different approach.</p> <pre><code>&lt;html&gt; &lt;script type="text/javascript"&gt; // SuccessHandler to close form function close() {google.script.host.close();} &lt;/script&gt; &lt;body&gt; &lt;div&gt; &lt;form&gt; &lt;label&gt;First Name&lt;/label&gt; &lt;input name="fname" type="text" maxlength="255" value="&lt;?= fname ?&gt;"/&gt; &lt;input type="button" value="Submit" onclick="google.script.run .withSuccessHandler(close) .processForm(this.parentNode)"/&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload