【问题标题】:google apps script sidebar form Send button not working谷歌应用程序脚本侧边栏表单发送按钮不起作用
【发布时间】:2019-06-25 23:38:47
【问题描述】:

我正在为工作表创建一个谷歌插件。我正在处理的侧边栏旨在作为一种帮助票提交,但在我开发这部分内容之前,我没有在表单中获得提交按钮来调用我想要构建的 javascript 函数。

我已经从 html 按钮调用中删除了所有表单数据以激活 Logger.log。没有骰子。 我创建了一个完全独立(并且非常简单)的按钮来调用不同的函数来调用 Logger.log。这也没有奏效。 我已经仔细检查了表单数据、发送调用和函数。 我确保函数的名称 (sendMsg) 是唯一的。 我认为问题可能不在我的代码中,而是以其他方式连接了 html 和 javascript (.gs)。

这里是html表单:

<div class="block form-group">
<form>
  <label for="reason">Purpose of Contact</label>
  <select id="reason">
    <option selected>Help Request</option>
    <option>Feature Request</option>
    <option>Error Report</option>
    <option>Other</option>
  </select>
  <label for="email">Email</label>
  <input type="text" id="email" style="width: 200px;">
  <label for="phone">Phone</label>
  <input type="text" id="phone" style="width: 120px;" value = "optional">
<br>
    <label for="translated-text">
      <b>Message</b></label>
    <textarea id="userMsg" rows="15" cols="35">
    </textarea>
<br>
<input id="app" name="appSrc" type="hidden" value="COE">
<input type="button" class="action" name="helpRequest" value="SEND" onClick="google.script.run.sendMsg( 
           document.getElementById('reason').value,
           document.getElementById('email').value,
           document.getElementById('phone').value,
           document.getElementById('userMsg').value,
           document.getElementById('appSrc').value
   )" />
   </form>
   </div>

这里是调用的函数:

function sendMsg(appSrc,reason,email,phone,userMsg) {
    appV = appSrc;
    reasonV = reason;
    emailV = email;
    phoneV = phone;
    userMsgV = userMsg;
    Logger.log('cheese');
}

现在表单应该只生成一个 Logger.log 消息。此时没有任何反应。

【问题讨论】:

  • 谢谢。我有一种感觉,这很简单。我现在收到了 Logger.log 反馈,这将使我能够继续前进。

标签: javascript html forms google-apps-script google-sheets


【解决方案1】:
  • 在您的情况下,当单击“发送”按钮时,Google Apps 脚本端sendMsg() 的脚本不起作用。
    • 你想运行sendMsg()

如果我的理解是正确的,那么这次修改呢?

修改点:

  • 当我看到&lt;input id="app" name="appSrc" type="hidden" value="COE"&gt; 时,appSrc 不是 id。这样,document.getElementById('appSrc').value 出现错误,sendMsg() 不起作用。因此,如果您的脚本被修改,例如,请使用app

发件人:

document.getElementById('appSrc').value

收件人:

document.getElementById('app').value

或者

发件人:

<input id="app" name="appSrc" type="hidden" value="COE">

收件人:

<input id="appSrc" name="appSrc" type="hidden" value="COE">

如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

【讨论】:

    【解决方案2】:

    如果有人遇到与我相同的问题...onpress 似乎在这里不起作用。我不得不把它改成onclick

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多