简体   繁体   English

Google表格:HTML表单<input id>到Google脚本getElementById

[英]Google Sheets: HTML form <input id> to Google Scripts getElementById

CONTEXT语境

  • I am working on Google Sheets with Google Scripts (JS) and HTML forms我正在使用带有Google脚本(JS)和HTML表单的Google表格
  • There are three pieces of code working together有三段代码协同工作
  • (JS/GS - Code.gs) function openForm() which opens the html form on Google Sheets (JS / GS-Code.gs)函数openForm()在Google表格上打开html表单
  • (HTML - htmlForm.html) simplified form with one input and a submit button (HTML-htmlForm.html)具有一个输入和一个提交按钮的简化形式
  • (JS/GS - Code.gs) function submitForm() which should take the input and pasted onto a spreadsheet (JS / GS-Code.gs)函数submitForm() ,该函数应该接受输入并粘贴到电子表格上

STATUS/ISSUES状态/问题

  • openForm works fine and opens the form openForm可以正常工作并打开表单
  • submitForm functionality with the spreadsheet works fine when the value is coming from a different cell or set manually当值来自其他单元格或手动设置时,电子表格的submitForm功能可以正常工作
  • htmlForm does work, as in, looks as intended htmlForm确实可以按预期工作
  • The main issue is the connection between htmlForm and submitForm .主要的问题是与HtmlForm控件submitForm连接 The input project input is not carried from HTML to GS, from the form to the spreadsheet.输入项目输入不是从HTML到GS,也不是从表单到电子表格。

I don't really know why, and I'm not very familiar with scripts within HTML, so I'm not sure if this one actually works.我真的不知道为什么,而且我对HTML中的脚本不是很熟悉,所以我不确定这个脚本是否真正起作用。

CODE代码

 function openForm() { var s=SpreadsheetApp.getActive(); var htmlDlg = HtmlService.createHtmlOutputFromFile('htmlForm') .setSandboxMode(HtmlService.SandboxMode.IFRAME) .setWidth(750) .setHeight(450); SpreadsheetApp.getUi() .showModalDialog(htmlDlg, 'New tasks for new campaign setup 📝'); } ////////// function submitForm(formObject) { var project = formObject.project; // and so on... var s = SpreadsheetApp.getActiveSpreadsheet(); var ss = s.getSheetByName("Support"); // Enter sheet name var rangeProject = ss.getRange('AA2'); rangeProject.setValue(project) }

 <p>Form</p> <form id="briefForm" onsubmit="handleFormSubmit()"> <input type="text" id="project"> <input type="submit" id="submitbttn"> </form> <!-- Script down here --> <script> window.closeDia = function() { var formObject = { project: document.getElementById('project').value, // other form input fields... } google.script.run.sendBrief(formObject); }; </script>

CONTEXT语境

  • I am working on Google Sheets with Google Scripts (JS) and HTML forms我正在使用带有Google脚本(JS)和HTML表单的Google表格
  • There are three pieces of code working together有三段代码协同工作
  • (JS/GS - Code.gs) function openForm() which opens the html form on Google Sheets (JS / GS-Code.gs)函数openForm()在Google表格上打开html表单
  • (HTML - htmlForm.html) simplified form with one input and a submit button (HTML-htmlForm.html)具有一个输入和一个提交按钮的简化形式
  • (JS/GS - Code.gs) function submitForm() which should take the input and pasted onto a spreadsheet (JS / GS-Code.gs)函数submitForm() ,该函数应该接受输入并粘贴到电子表格上

STATUS/ISSUES状态/问题

  • openForm works fine and opens the form openForm可以正常工作并打开表单
  • submitForm functionality with the spreadsheet works fine when the value is coming from a different cell or set manually当值来自其他单元格或手动设置时,电子表格的submitForm功能可以正常工作
  • htmlForm does work, as in, looks as intended htmlForm确实可以按预期工作
  • The main issue is the connection between htmlForm and submitForm .主要的问题是与HtmlForm控件submitForm连接 The input project input is not carried from HTML to GS, from the form to the spreadsheet.输入项目输入不是从HTML到GS,也不是从表单到电子表格。

I don't really know why, and I'm not very familiar with scripts within HTML, so I'm not sure if this one actually works.我真的不知道为什么,而且我对HTML中的脚本不是很熟悉,所以我不确定这个脚本是否真正起作用。

CODE代码

 function openForm() { var s=SpreadsheetApp.getActive(); var htmlDlg = HtmlService.createHtmlOutputFromFile('htmlForm') .setSandboxMode(HtmlService.SandboxMode.IFRAME) .setWidth(750) .setHeight(450); SpreadsheetApp.getUi() .showModalDialog(htmlDlg, 'New tasks for new campaign setup 📝'); } ////////// function submitForm(formObject) { var project = formObject.project; // and so on... var s = SpreadsheetApp.getActiveSpreadsheet(); var ss = s.getSheetByName("Support"); // Enter sheet name var rangeProject = ss.getRange('AA2'); rangeProject.setValue(project) }

 <p>Form</p> <form id="briefForm" onsubmit="handleFormSubmit()"> <input type="text" id="project"> <input type="submit" id="submitbttn"> </form> <!-- Script down here --> <script> window.closeDia = function() { var formObject = { project: document.getElementById('project').value, // other form input fields... } google.script.run.sendBrief(formObject); }; </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM