Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从HTML组合框中提取值并传递给函数_Html_Google Apps Script - Fatal编程技术网

从HTML组合框中提取值并传递给函数

从HTML组合框中提取值并传递给函数,html,google-apps-script,Html,Google Apps Script,我正在使用谷歌应用程序脚本在谷歌文档中构建自定义用户界面 UI是用HTMl构建的。我试图将html组合框的值传递给服务器端函数 我缺少什么来获取组合框的值并传递它 .html 我知道服务器函数被正确调用,因为showAlert函数正在运行。同样的document.getElementByID()方法在html文件的另一部分中使用文本框时工作正常。组合框是否有任何不同?如果要避免使用脚本标记,可以在表单标记中添加onsubmit属性: <form id="cboPhase" onsubmit

我正在使用谷歌应用程序脚本在谷歌文档中构建自定义用户界面

UI是用HTMl构建的。我试图将html组合框的值传递给服务器端函数

我缺少什么来获取组合框的值并传递它

.html


我知道服务器函数被正确调用,因为showAlert函数正在运行。同样的
document.getElementByID()
方法在html文件的另一部分中使用文本框时工作正常。组合框是否有任何不同?

如果要避免使用脚本标记,可以在表单标记中添加
onsubmit
属性:

<form id="cboPhase" onsubmit="google.script.run
 .phaseName(this)">
在您的情况下,表单中只有一个选择框。如果表单中有更多的输入元素,那么数组中就会有多个值。我在服务器中得到的结果是:(假设我选择了“构造”选项):

添加输入字段后,您将得到以下结果:

{=[Construction, test input]}
我认为您不能在
google.script.run.funcName()
中使用
document.getElementById('cboPhase').value
作为参数。它正在返回NULL

如果不传递对象,则传递的是值:

document.getElementById('cboPhase').value
如果没有名为
按钮链接器()
在它中,当HTML被提供给浏览器时,它将有一个错误

未捕获引用错误:未定义buttonClicker

因此,如果您想要一个带有SuccessHandler的
,那么您需要一个
标记。如果要使用
,那么最好将
google.script.run
放入脚本标记中,而不是输入标记的onClick属性

<script>
  function fncCallServerCode() {
    var valueToPass = document.getElementById('cboPhase').value;

    google.script.run
     .withSuccessHandler(buttonClicker)
     .phaseName(valueToPass);
  };

  function buttonClicker(argReturnValue) {
    alert('The code ran: ' + argReturnValue);
  }
</script>

函数fncCallServerCode(){
var valueToPass=document.getElementById('cboPhase').value;
google.script.run
.使用SuccessHandler(按钮点击器)
.相位名称(valueToPass);
};
函数按钮链接器(argReturnValue){
警报('运行的代码:'+argReturnValue);
}
您的输入需要如下所示:

<div>
  <input type="submit" class="button redButton" value="Submit" onclick="fncCallServerCode()">
</div>


我的理解是,谈话是这样进行的。客户端>>服务器>>客户端。哪个是html ui>>google.script.run.GSfunctionName()>>.onSuccessHandler(htmlta)如果我想将参数传递给.gs文件,我应该在初始的.script.run中包含该参数,对吗?google.script.run(document.getElementById(elementIdName).value/or.textYes正确。我只是把一个变量名作为要传递的参数。好的,澄清一下。如果我不需要一个成功的参数。在这个例子中,我应该能够在html端使用onclick=“google.script.run.phaseName(cboPhase)”>。gs将用phaseName处理这个参数(你在这里做什么){
{=[Construction, test input]}
document.getElementById('cboPhase').value
<script>
  function fncCallServerCode() {
    var valueToPass = document.getElementById('cboPhase').value;

    google.script.run
     .withSuccessHandler(buttonClicker)
     .phaseName(valueToPass);
  };

  function buttonClicker(argReturnValue) {
    alert('The code ran: ' + argReturnValue);
  }
</script>
<div>
  <input type="submit" class="button redButton" value="Submit" onclick="fncCallServerCode()">
</div>