Google Apps脚本-我的按钮不会调用javascript函数

doinxwow  于 2023-01-19  发布在  Java
关注(0)|答案(1)|浏览(158)

这是用户输入表单的html代码:

<!DOCTYPE html>
<html>

<head>

  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

</head>

<body>
  
  <div class="marginauto" align="middle">

  <style>
    .marginauto {
    margin: 10px auto 20px;
    display: block;
    }
  </style>
  
  <h1>
    <img class="marginauto" align="middle" src="https://drive.google.com/uc?export=view&id=********" alt="*****">
    Fabrication Time Record
  </h1 >

  <h2 class="marginauto" align="middle">
    Information
  </h2>

    <label for="fname">First name:</label><br>
    <input type="text" id="fname" name="fname"><br>
    <label for="lname">Last name:</label><br>
    <input type="text" id="lname" name="lname"><br>
    <label for="jnum">Job number:</label><br>
    <input type="text" id="jnum" name="jnum"><br>

  <h2>
    Operation
  </h2>

    <input type="radio" id="cut" name="operation" value="cut">
    <label for="cut">Cut</label><br>
    <input type="radio" id="drill" name="operation" value="drill">
    <label for="drill">Drill</label><br>
    <input type="radio" id="fitup" name="operation" value="fitUp">
    <label for="fitup">Fit Up</label><br>
    <input type="radio" id="weld" name="operation" value="weld">
    <label for="weld">Weld</label><br>

  <h2>
    Comments
  </h2>

  <input type="text" id="comment"><br>

  <br>
  <button id="clockin">Clock in</button>

  </div>

    <script type="text/javascript">

      document.getElementById("clockin").addEventListener("click",addLine);

      function addLine(){

      var firstName = document.getElementById("fname");
      var lastName = document.getElementById("lname");
      var operation = document.getElementByName("operation");

      var entry = {
        entry.fn = firstName.value;
        entry.ln = lastName.value;
        entry.op = operation.value;

      }

        google.script.run.addEntry(entry);
        firstName.value = "";
        lastName.value = "";

      }

    </script>
            
</body>

</html>

这是一个从html获取用户输入并(理想情况下)将其传输到谷歌电子表格的脚本:

function doGet(e){

  Logger.log(e);
  
  var html = HtmlService.createHtmlOutputFromFile("userForm");
  html.setTitle("Record Time")
  return(html)

}

function addEntry(entry){

  Logger.log("Someone clicked the button");

  var ssid = "1E81*****************QBmW1o4Q";
  var ss = SpreadsheetApp.openById(ssid);
  SpreadsheetApp.setActiveSpreadsheet(ss);
  var database = ss.getSheetByName("Database");
  SpreadsheetApp.setActiveSheet(database);

  database.appendRow = ([entry]);

}

当我点击按钮时,什么也没有发生,我确信我调用的是正确的电子表格,因为我可以从doGet()函数中读写,但addLine()函数似乎有问题,我找不到。
任何帮助是非常感谢,我是非常新的网络应用程序开发。
我想要的是按钮将数据从一些文本输入字段传输到谷歌电子表格。我使用了多个不同的按钮语法,但不能什么都不发生。

cuxqih21

cuxqih211#

如果要将对象传递给addEntry,则应传递一个数组。
变更

var entry = {
    entry.fn = firstName.value;
    entry.ln = lastName.value;
    entry.op = operation.value;
  };

var entry = [
    firstName.value,
    lastName.value,
    operation.value
  ];

相关问题