簡體   English   中英

從HTML頁面運行Google表格應用腳本功能並返回表單值

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

我正在嘗試將用戶在Google應用程序腳本中的網頁上輸入的表單的值返回給函數,然后用響應通知用戶。

這是我的應用腳本

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!'); 
}

我正在嘗試讓checkLogin啟動。 這是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>

我的錯誤是我將OK和Close函數調用混在一起。 應該是

<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM