简体   繁体   English

从HTML页面运行Google表格应用脚本功能并返回表单值

[英]Running a Google Sheets App script function from an HTML page with form values returned

I'm trying to return the values that a user enters into a form on a webpage in a google app script to a function and then notify the user with a response. 我正在尝试将用户在Google应用程序脚本中的网页上输入的表单的值返回给函数,然后用响应通知用户。

Here is my app script 这是我的应用脚本

function onOpen() {
   openLogin();
   SpreadsheetApp.getUi()
     .createMenu('Dialog')
     .addItem('Open', 'openLogin')
     .addToUi()
}

function openLogin() {
   var html = HtmlService.createHtmlOutputFromFile('index');
   SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
       .showModalDialog(html, 'Login Form');
}

function checkLogin() {
   SpreadsheetApp.getUi().alert('Hello, world!'); 
}

I'm trying to get checkLogin to fire off. 我正在尝试让checkLogin启动。 Here is the HTML code. 这是HTML代码。

<!DOCTYPE html>
<html>
<head>
   <base target="_top">
</head>
<body>
  <form>    
    First name:&nbsp;&nbsp;
    <input type="text" name="user_name"><br><br>
    Last name:&nbsp;&nbsp;
    <input type="password" name="user_password"><br><br>
    Staff or Student?
    <br>

    <input type="radio" name="staff" value="staff" checked> Staff<br>
    <input type="radio" name="student" value="student"> Student<br>
    <br><br>

    <input type="button" value="OK"
    onclick="google.script.host.close()" />

    <input type="button" value="Close"
    onclick="google.script.run.checkLogin()" />

  </form> 
</body>
</html>

My mistake, I had the OK and Close function calls mixed up. 我的错误是我将OK和Close函数调用混在一起。 It should have been 应该是

<input type="button" value="OK"
onclick="google.script.run.checkLogin()" />

<input type="button" value="Close"
onclick="google.script.host.close()" />

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

相关问题 Google表格应用脚本HTML页面隐藏关闭(X)按钮 - Google Sheets App Script HTML Page Hide close (X) button 根据Google Apps脚本函数的返回值以HTML显示单选按钮 - Display Radio Buttons in HTML from Google Apps Script Function's Returned Values 用户如何从html表单中收集Google应用程序脚本中变量输入值的值? - userHow to collect the values from html form for variable input values in google app script? Google表格应用脚本HTML的onload无法正常工作 - Google Sheets App Script Html onload not working 从JavaScript函数访问返回值会导致HTML页面重新加载 - Accessing Returned Values From JavaScript Function Causes HTML Page to Reload 谷歌表格应用程序脚本如果其他 Function - Google Sheets App Script If Else Function 将数据从 HTML 表单发送到 Google 表格 - Sending data from HTML form to Google Sheets 从 Google 表格填充 HTML 表单 - Populate HTML form from Google Sheets 从 Google 表格中提取数据以在 Google 脚本上制作甘特图并将 HTML 作为网络应用程序提供 - Ingest data from Google sheets to make a gantt chart on Google script and serve the HTML as web app 我可以在Google表格中创建一个函数并从网络应用程序Google Apps脚本中使用它吗? - Can I create a function in Google Sheets and use it from a web app Google Apps Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM