简体   繁体   English

从网络应用程序收集数据到谷歌表

[英]Collecting data to a google sheet from a webapp

I have a basic sheet with the jSignature code that works and collects the data from the webapp when published.我有一个带有 jSignature 代码的基本工作表,可以在发布时从 webapp 收集数据。 I wanted to add on this so had created another sheet and followed the same layout.我想添加这个,所以创建了另一个工作表并遵循相同的布局。 Admittedly, I am just a copy and paste coder at this time.诚然,此时我只是一个复制和粘贴编码员。 I understand a lot of what I'm reading, but some things just don't register to me yet.我明白我正在阅读的很多东西,但有些东西还没有注册给我。 I can't for the life of me figure out why the first sheet works and the second doesn't.我一生都无法弄清楚为什么第一张工作表有效而第二张无效。 *the working sheet only works with the folder id put in, I believe, so you'll have to replace that. *工作表仅适用于放入的文件夹 ID,我相信,因此您必须替换它。

Here is the link to the sheet that works (hopefully all can view): https://drive.google.com/open?id=1uJk7ZkOKUp1Z8afTxVZ1uRdoTCxa08MRYQtVcOmTOAk这是工作表的链接(希望所有人都能查看): https : //drive.google.com/open?id=1uJk7ZkOKUp1Z8afTxVZ1uRdoTCxa08MRYQtVcOmTOAk

and the one that doesn't: https://drive.google.com/open?id=1tINd-54djeIhfOL3laLNXiohNlAPONb6MDA6Y_xQUKI还有一个没有: https : //drive.google.com/open?id=1tINd-54djeIhfOL3laLNXiohNlAPONb6MDA6Y_xQUKI

If for whatever reason those links don't work, here are the code snippets:如果由于某种原因这些链接不起作用,这里是代码片段:

Working Code.gs工作代码.gs

function showDialog() {
  var html = HtmlService.createHtmlOutputFromFile('jSignature')
    .setWidth(400)
    .setHeight(300);
   SpreadsheetApp.getUi()
  .showModalDialog(html, 'Your Signature is Required');
}

function doGet() {
  return HtmlService
      .createTemplateFromFile('jSignature')
      .evaluate();
}

function saveImage(bytes, sign){
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Register');
  var dateObj = Date.now();
  var bytes = bytes.split(",")
  var blob = Utilities.newBlob(Utilities.base64Decode(bytes[1]), 'image/png');
  var fileName = blob.setName("Signature "+dateObj).getName();
  var sigFolder = DriveApp.getFolderById("myfolderid"); //replace with your folder id
  var url = sigFolder.createFile(blob).getId();
  Logger.log(url)
  var name = sign.username;
  var employeenumber = sign.useremployeenumber;
  var signature = ss.insertImage(blob,4,ss.getLastRow()+1);
  signature.setWidth(500);
  signature.setHeight(20);
  signature
  var imageCell = ss.getRange(ss.getLastRow()+1, 1, 1, 3).setValues([[Date(), name,employeenumber]]);
}

Working .html工作 .html

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/willowsystems/jSignature/master/libs/jSignature.min.js"></script>
<body>
<form id="customerForm">
Please sign your name in the pad below: <br>
Full Name: <input type="text" name="username"><br>
Employee Number: <input type="employeenumber" name="useremployeenumber"><br><br>
Signature:
<div id="signature"></div><br>
<img id="rendered" src="" style="display:none">
<input type="Submit" value="Save" onclick="renderSignature();saveImage();"/>
</form>
</body>
<script>
  document.getElementById("signature").style.border = "1px solid black";

  $("#signature").jSignature({
    'background-color': 'transparent',
    'decor-color': 'transparent'
  });

  function renderSignature(){
    $("img#rendered").attr("src",$('#signature').jSignature('getData','default'));
  }

  function saveImage(e){ //This sends the image src to saveImages function
    var bytes = document.getElementById('rendered').src;
    console.log(bytes);
    var sign = {
      username: document.getElementsByName('username')[0].value,
      useremployeenumber: document.getElementsByName('useremployeenumber')[0].value
    };
    google.script.run.saveImage(bytes, sign);
    return
  } 
  window.onload=function(){
  google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.saveImage(bytes, sign);
}

</script>
</html>

non-working code.gs非工作代码.gs

function showDialog() {
  var html = HtmlService.createHtmlOutputFromFile('jSignature')
    .setWidth(400)
    .setHeight(300);
   SpreadsheetApp.getUi()
  .showModalDialog(html, 'Your Signature is Required');
}

function doGet() {
  return HtmlService
      .createTemplateFromFile('jSignature')
      .evaluate();
}

function saveImage(bytes, sign){
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('FormResponse');
  var dateObj = Date.now();
  var bytes = bytes.split(",")
  var blob = Utilities.newBlob(Utilities.base64Decode(bytes[1]), 'image/png');
  var fileName = blob.setName("Signature "+dateObj).getName();
  var sigFolder = DriveApp.getFolderById("myfolderid"); //replace with your folder id
  var url = sigFolder.createFile(blob).getId();
  Logger.log(url)
  var carrier = sign.carrier;
  var address = sign.address;
  var dname = sign.dname;
  var dnum = sign.dnum;
  var date = sign.date;
  var time = sign.time;
  var tractortruck = sign.tractortruck;
  var odom = sign.odom;
  var aircompressor = sign.aircompressor;
  var airlines = sign.airlines;
  var BeltsandHoses = sign.BeltsandHoses;
  var Body = sign.Body;
  var BrakeAccessories = sign.BrakeAccessories;
  var BrakesParking = sign.BrakesParking;
  var BrakesService = sign.BrakesService;
  var Clutch = sign.Clutch;
  var CouplingDevices = sign.CouplingDevices;
  var DefrosterHeater = sign.DefrosterHeater;
  var DriveLine = sign.DriveLine;
  var Engine = sign.Engine;
  var Exhaust = sign.Exhaust;
  var FifthWheel = sign.FifthWheel;
  var FluidLevels = sign.FluidLevels;
  var FrameandAssembly = sign.FrameandAssembly;
  var FrontAxle = sign.FrontAxle;
  var FuelTanks = sign.FuelTanks;
  var Horn = sign.Horn;
  var Lights = sign.Lights;
  var Mirrors = sign.Mirrors;
  var Muffler = sign.Muffler;
  var OilPressure = sign.OilPressure;
  var Radiator = sign.Radiator;
  var RearEnd = sign.RearEnd;
  var Reflectors = sign.Reflectors;
  var SafetyEquipment = sign.SafetyEquipment;
  var Starter = sign.Starter;
  var Steering = sign.Steering;
  var SuspensionSystem = sign.SuspensionSystem;
  var TireChains = sign.TireChains;
  var Tires = sign.Tires;
  var Transmission = sign.Transmission;
  var TripRecorder = sign.TripRecorder;
  var WheelsandRims = sign.WheelsandRims;
  var Windows = sign.Windows;
  var WindshieldWipers = sign.WindshieldWipers;
  var Other = sign.Other;
  var signature = ss.insertImage(blob,47,ss.getLastRow()+1);
  signature.setWidth(500);
  signature.setHeight(20);
  signature
  var imageCell = ss.getRange(ss.getLastRow()+1, 1, 1, 46).setValues([[carrier, address, dname, dnum, date, time, tractortruck, odom, aircompressor, airlines, BeltsandHoses, Body, BrakeAccessories, BrakesParking, BrakesService, Clutch, CouplingDevices, DefrosterHeater, DriveLine, Engine, Exhaust, FifthWheel, FluidLevels, FrameandAssembly, FrontAxle, FuelTanks, Horn, Lights, Mirrors, Muffler, OilPressure, Radiator, RearEnd, Reflectors, SafetyEquipment, Starter, Steering, SuspensionSystem, TireChains, Tires, Transmission, TripRecorder, WheelsandRims, Windows, WindshieldWipers, Other]]);
}

non-working html非工作 html

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=2, maximum-scale=1, user-scalable=0"/></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/willowsystems/jSignature/master/libs/jSignature.min.js"></script>
<style>
body {
  font-family: Arial;
}

input[type=text], select {
  width: 100%;
  height: 100px;
  padding: 12px 20px;
  margin: 8px 0;
  display: block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 2em;
}
input[type=number], select {
  width: 100%;
  height: 100px;
  padding: 12px 20px;
  margin: 8px 0;
  display: block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 2em;
}
input[type=date], select {
  width: 100%;
  height: 100px;
  padding: 12px 20px;
  margin: 8px 0;
  display: block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 2em;
}

input[type=time], select {
  width: 100%;
  height: 100px;
  padding: 12px 20px;
  margin: 8px 0;
  display: block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 2em;
}

input[type=submit] {
  width: 100%;
  background-color: #4CAF50;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1em;
}
input[type=radio] {
  width: 80px;
  height: 80px;
}

input[type=submit]:hover {
  background-color: #45a049;
}

#signature {
  width: 100%;
  height: 300px;
  border: 2px solid #ccc;
  border-radius: 4px;
  }
#Inspection th, #Inspection td {
  border: 2px solid #ddd;
  font-size: 30px;
  font-weight: bold;
  }
#Inspection td {
  width: 60%;
  }
#Inspection th {
  width: 20%;
  }
#customerForm {
  font-size: 2em;
  font-weight: Bold;
  }
  ::placeholder {
  font-size: 1em;
  }

</style>
<body>
<center><h1><big><big>DRIVER VEHICLE INSPECTION REPORT</big></big></h1>
<h5>AS REQUIRED BY THE D.O.T. FEDERAL MOTOR CARRIER SAFETY REGULATIONS</h5></center><br>
<form id="customerForm">
<div class="container">
  <form action="/action_page.php">
  <label for="carrier">Carrier:</label>
    <select id="carrier" name="carrier" required>
      <option value="My Company">My Company</option>   
      </select><br>
      <label for="address">Address:</label>
    <select id="address" name="address" required>
      <option value="" disabled selected>Select your location</option>
      <option value="PDX">PDX</option>
      <option value="SEA">SEA</option>
      <option value="SFO">SFO</option>
      </select><br>
      <label for="Driver name">Driver Performing Inspection:</label>
  <input type="text" id="dname" name="drivername" placeholder="Your full name" required><br>
  <label for="Driver Employee ID number">Driver's Employee Number:</label><br>
  <input type="number" id="dnum" name="drivernumber" placeholder="Your employee number" required><br><br>
  <label for="Date">Date Performed:</label><br>
  <input type="date" id="date" name="date" required><br><br>
  <label for="Time">Time Performed:</label><br>
  <input type="time" id="time" name="time" value="now" required><br><br>
  <label for="Tractor/Truck#">Tractor / Truck #:</label><br>
  <input type="number" id="tractor/truck" name="tractor/truck" placeholder="Your vehicle number" required><br><br>
  <label for="Odometer">Odometer Reading:</label><br>
  <input type="number" id="odom" name="odometer reading" placeholder="Vehicle odometer reading" required><br><br>
  <center><h3>Tractor / Truck Inspection:</h3><br></center>
  <table id= "Inspection">
  <tr>
  <td></td>
  <th>Satisfactory</th>
  <th>Unsatisfactory</th>
  </tr>
  <tr>
  <td><label for="Air Compressor">Air Compressor</label></td>
  <th><input type="radio" id="air compressor" name="air compressor" value="Sat" required></th>
  <th><input type="radio" id="air compressor" name="air compressor" value="Unsat" required></th>
  </tr>
  <tr>
  <td><label for="Air Lines">Air Lines</label></td>
  <th><input type="radio" id="air lines" name="air lines" value="Sat" required></th>
  <th><input type="radio" id="air lines" name="air lines" value="Unsat" required></th>
  </tr>
  <tr>
  <td><label for="Battery">Battery</label></td>
  <th><input type="radio" id="Battery" name="Battery" value="Sat" required></th>
  <th><input type="radio" id="Battery" name="Battery" value="Unsat" required></th>
  </tr>
  <tr>
  <td><label for="Belts and Hoses">Belts and Hoses</label></td>
  <th><input type="radio" id="Belts and Hoses" name="Belts and Hoses" value="Sat" required></th>
  <th><input type="radio" id="Belts and Hoses" name="Belts and Hoses" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Body">Body</label></td>
  <th><input type="radio" id="Body" name="Body" value="Sat"required></th>
  <th><input type="radio" id="Body" name="Body" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Brake Accessories">Brake Accessories</label></td>
  <th><input type="radio" id="Brake Accessories" name="Brake Accessories" value="Sat"required></th>
  <th><input type="radio" id="Brake Accessories" name="Brake Accessories" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Brakes, Parking">Brakes, Parking</label></td>
  <th><input type="radio" id="Brakes, Parking" name="Brakes, Parking" value="Sat"required></th>
  <th><input type="radio" id="Brakes, Parking" name="Brakes, Parking" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Brakes, Service">Brakes, Service</label></td>
  <th><input type="radio" id="Brakes, Service" name="Brakes, Service" value="Sat"required></th>
  <th><input type="radio" id="Brakes, Service" name="Brakes, Service" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Clutch">Clutch</label></td>
  <th><input type="radio" id="Clutch" name="Clutch" value="Sat"required></th>
  <th><input type="radio" id="Clutch" name="Clutch" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Coupling Devices">Coupling Devices</label></td>
  <th><input type="radio" id="Coupling Devices" name="Coupling Devices" value="Sat"required></th>
  <th><input type="radio" id="Coupling Devices" name="Coupling Devices" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Defroster/Heater">Defroster/Heater</label></td>
  <th><input type="radio" id="Defroster/Heater" name="Defroster/Heater" value="Sat"required></th>
  <th><input type="radio" id="Defroster/Heater" name="Defroster/Heater" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Drive Line">Drive Line</label></td>
  <th><input type="radio" id="Drive Line" name="Drive Line" value="Sat"required></th>
  <th><input type="radio" id="Drive Line" name="Drive Line" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Engine">Engine</label></td>
  <th><input type="radio" id="Engine" name="Engine" value="Sat"required></th>
  <th><input type="radio" id="Engine" name="Engine" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Exhaust">Exhaust</label></td>
  <th><input type="radio" id="Exhaust" name="Exhaust" value="Sat"required></th>
  <th><input type="radio" id="Exhaust" name="Exhaust" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Fifth Wheel">Fifth Wheel</label></td>
  <th><input type="radio" id="Fifth Wheel" name="Fifth Wheel" value="Sat"required></th>
  <th><input type="radio" id="Fifth Wheel" name="Fifth Wheel" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Fluid Levels">Fluid Levels</label></td>
  <th><input type="radio" id="Fluid Levels" name="Fluid Levels" value="Sat"required></th>
  <th><input type="radio" id="Fluid Levels" name="Fluid Levels" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Frame and Assembly">Frame and Assembly</label></td>
  <th><input type="radio" id="Frame and Assembly" name="Frame and Assembly" value="Sat"required></th>
  <th><input type="radio" id="Frame and Assembly" name="Frame and Assembly" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Front Axle">Front Axle</label></td>
  <th><input type="radio" id="Front Axle" name="Front Axle" value="Sat"required></th>
  <th><input type="radio" id="Front Axle" name="Front Axle" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Fuel Tanks">Fuel Tanks</label></td>
  <th><input type="radio" id="Fuel Tanks" name="Fuel Tanks" value="Sat"required></th>
  <th><input type="radio" id="Fuel Tanks" name="Fuel Tanks" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Horn">Horn</label></td>
  <th><input type="radio" id="Horn" name="Horn" value="Sat"required></th>
  <th><input type="radio" id="Horn" name="Horn" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Lights">Lights -<br>&nbsp;&nbsp;&nbsp;&nbsp;Head/Stop<br>&nbsp;&nbsp;&nbsp;&nbsp;Tail/Dash<br>&nbsp;&nbsp;&nbsp;&nbsp;Turn Indicators<br>&nbsp;&nbsp;&nbsp;&nbsp;Clearance/Marker</label></td>
  <th><input type="radio" id="Lights" name="Lights" value="Sat"required></th>
  <th><input type="radio" id="Lights" name="Lights" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Mirrors">Mirrors</label></td>
  <th><input type="radio" id="Mirrors" name="Mirrors" value="Sat"required></th>
  <th><input type="radio" id="Mirrors" name="Mirrors" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Muffler">Muffler</label></td>
  <th><input type="radio" id="Muffler" name="Muffler" value="Sat"required></th>
  <th><input type="radio" id="Muffler" name="Muffler" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Oil Pressure">Oil Pressure</label></td>
  <th><input type="radio" id="Oil Pressure" name="Oil Pressure" value="Sat"required></th>
  <th><input type="radio" id="Oil Pressure" name="Oil Pressure" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Radiator">Radiator</label></td>
  <th><input type="radio" id="Radiator" name="Radiator" value="Sat"required></th>
  <th><input type="radio" id="Radiator" name="Radiator" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Rear End">Rear End</label></td>
  <th><input type="radio" id="Rear End" name="Rear End" value="Sat"required></th>
  <th><input type="radio" id="Rear End" name="Rear End" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Reflectors">Reflectors</label></td>
  <th><input type="radio" id="Reflectors" name="Reflectors" value="Sat"required></th>
  <th><input type="radio" id="Reflectors" name="Reflectors" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Safety Equipment">Safety Equipment -<br>&nbsp;&nbsp;&nbsp;&nbsp;Fire Extinguisher<br>&nbsp;&nbsp;&nbsp;&nbsp;Flags/Flares/Fusees<br>&nbsp;&nbsp;&nbsp;&nbsp;Reflective Triangles<br>&nbsp;&nbsp;&nbsp;&nbsp;Spare Bulbs and Fuses<br>&nbsp;&nbsp;&nbsp;&nbsp;Spare Seal Beam</label></td>
  <th><input type="radio" id="Safety Equipment" name="Safety Equipment" value="Sat"required></th>
  <th><input type="radio" id="Safety Equipment" name="Safety Equipment" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Starter">Starter</label></td>
  <th><input type="radio" name="Starter" value="Sat"required></th>
  <th><input type="radio" name="Starter" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Steering">Steering</label></td>
  <th><input type="radio" id="Steering" name="Steering" value="Sat"required></th>
  <th><input type="radio" id="Steering" name="Steering" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Suspension System">Suspension System</label></td>
  <th><input type="radio" id="Suspension System" name="Suspension System" value="Sat"required></th>
  <th><input type="radio" id="Suspension System" name="Suspension System" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Tire Chains">Tire Chains</label></td>
  <th><input type="radio" id="Tire Chains" name="Tire Chains" value="Sat"required></th>
  <th><input type="radio" id="Tire Chains" name="Tire Chains" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Tires">Tires</label></td>
  <th><input type="radio" id="Tires" name="Tires" value="Sat"required></th>
  <th><input type="radio" id="Tires" name="Tires" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Transmission">Transmission</label></td>
  <th><input type="radio" id="Transmission" name="Transmission" value="Sat"required></th>
  <th><input type="radio" id="Transmission" name="Transmission" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Trip Recorder">Trip Recorder</label></td>
  <th><input type="radio" id="Trip Recorder" name="Trip Recorder" value="Sat"required></th>
  <th><input type="radio" id="Trip Recorder" name="Trip Recorder" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Wheels and Rims">Wheels and Rims</label></td>
  <th><input type="radio" id="Wheels and Rims" name="Wheels and Rims" value="Sat"required></th>
  <th><input type="radio" id="Wheels and Rims" name="Wheels and Rims" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Windows">Windows</label></td>
  <th><input type="radio" id="Windows" name="Windows" value="Sat"required></th>
  <th><input type="radio" id="Windows" name="Windows" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Windshield Wipers">Windshield Wipers</label></td>
  <th><input type="radio" id="Windshield Wipers" name="Windshield Wipers" value="Sat"required></th>
  <th><input type="radio" id="Windshield Wipers" name="Windshield Wipers" value="Unsat"required></th>
  </tr>
  <tr>
  <td><label for="Other">Other</label></td>
  <th><input type="radio" id="Other" name="Other" value="Sat"required></th>
  <th><input type="radio" id="Other" name="Other" value="Unsat"required></th>
  </tr>
  </table><br>
<b><big>Signature:</big></b>
<div id="signature"></div><br>
<img id="rendered" src="" style="display:none">
<input type="submit" value="Submit and close" onclick="renderSignature();saveImage();"/>
</form>
</div>
</body>
<script>

  $("#signature").jSignature({
    'background-color': 'transparent',
    'decor-color': 'transparent',
  });

  function renderSignature(){
    $("img#rendered").attr("src",$('#signature').jSignature('getData','default'));
  }

  function saveImage(e){ //This sends the image src to saveImages function
    var bytes = document.getElementById('rendered').src;
    console.log(bytes);
    var sign = {
      carrier: document.getElementsByName('carrier')[0].value,
      address: document.getElementsByName('address')[0].value,
      dname: document.getElementsByName('dname')[0].value,
      dnum: document.getElementsByName('dnum')[0].value,
      date: document.getElementsByName('date')[0].value,
      time: document.getElementsByName('time')[0].value,
      tractortruck: document.getElementsByName('tractor/truck')[0].value,
      odom: document.getElementsByName('odom')[0].value,
      aircompressor: document.getElementsByName('air compressor')[0].value,
      airlines: document.getElementsByName('air lines')[0].value,
      BeltsandHoses: document.getElementsByName('Belts and Hoses')[0].value,
      Body: document.getElementsByName('Body')[0].value,
      BrakeAccessories: document.getElementsByName('Brake Accessories')[0].value,
      BeltsandHoses: document.getElementsByName('Belts and Hoses')[0].value,
      BrakesParking: document.getElementsByName('Brakes, Parking')[0].value,
      BrakesService: document.getElementsByName('Brakes, Service')[0].value,
      Clutch: document.getElementsByName('Clutch')[0].value,
      CouplingDevices: document.getElementsByName('Coupling Devices')[0].value,
      DefrosterHeater: document.getElementsByName('Defroster/Heater')[0].value,
      DriveLine: document.getElementsByName('Drive Line')[0].value,
      Engine: document.getElementsByName('Engine')[0].value,
      Exhaust: document.getElementsByName('Exhaust')[0].value,
      FifthWheel: document.getElementsByName('Fifth Wheel')[0].value,
      FluidLevels: document.getElementsByName('Fluid Levels')[0].value,
      FrameandAssembly: document.getElementsByName('Frame and Assembly')[0].value,
      FrontAxle: document.getElementsByName('Front Axle')[0].value,
      FuelTanks: document.getElementsByName('Fuel Tanks')[0].value,
      Horn: document.getElementsByName('Horn')[0].value,
      Lights: document.getElementsByName('Lights')[0].value,
      Mirrors: document.getElementsByName('Mirrors')[0].value,
      Muffler: document.getElementsByName('Muffler')[0].value,
      OilPressure: document.getElementsByName('Oil Pressure')[0].value,
      Radiator: document.getElementsByName('Radiator')[0].value,
      RearEnd: document.getElementsByName('Rear End')[0].value,
      Reflectors: document.getElementsByName('Reflectors')[0].value,
      SafetyEquipment: document.getElementsByName('Safety Equipment')[0].value,
      Starter: document.getElementsByName('Starter')[0].value,
      Steering: document.getElementsByName('Steering')[0].value,
      SuspensionSystem: document.getElementsByName('Suspension System')[0].value,
      TireChains: document.getElementsByName('Tire Chains')[0].value,
      Tires: document.getElementsByName('Tires')[0].value,
      Transmission: document.getElementsByName('Transmission')[0].value,
      TripRecorder: document.getElementsByName('Trip Recorder')[0].value,
      WheelsandRims: document.getElementsByName('Wheels and Rims')[0].value,
      Windows: document.getElementsByName('Windows')[0].value,
      WindshieldWipers: document.getElementsByName('Windshield Wipers')[0].value,
      Other: document.getElementsByName('Other')[0].value
    };
    google.script.run.saveImage(bytes, sign);
    return
  }
  window.onload=function(){
  google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.saveImage(bytes, sign);
}
let date = new Date().toISOString().substr(0, 10);
document.querySelector("#date").value = date;

$(function(){     
  var d = new Date(),        
      h = d.getHours(),
      m = d.getMinutes();
  if(h < 10) h = '0' + h; 
  if(m < 10) m = '0' + m; 
  $('input[type="time"][value="now"]').each(function(){ 
    $(this).attr({'value': h + ':' + m});
  });
});
</script>
</html>

I am looking to publish this as a webapp and be able to collect the responses in the sheet.我希望将其发布为 Web 应用程序,并能够收集工作表中的回复。

Thank you.谢谢你。

There are two issues with your script:您的脚本有两个问题:

  1. you call你打电话
      ...
      dname: document.getElementsByName('dname')[0].value,
      dnum: document.getElementsByName('dnum')[0].value,
      ...

instead of代替

       ...
      dname: document.getElementsByName('drivername')[0].value,
      dnum: document.getElementsByName('drivernumber')[0].value,
      ...

but there are no elements with the names 'dname' and 'dnum' (don't mix up names with Ids...)但是没有名称为“dname”和“dnum”的元素(不要将名称与 Id 混淆...)

There are several wrong getElementsByName() calls - change them all.有几个错误的 getElementsByName() 调用 - 将它们全部更改。

  1. You call你打电话
    google.script.run.saveImage(bytes, sign);

both within function saveImage(e) and window.onload=function()function saveImage(e)window.onload=function()

Remove the second one - you don't need to call saveImage(bytes, sign) twice, and also within window.onload=function() bytes and sign are not defined.删除第二个 - 您不需要调用saveImage(bytes, sign)两次,并且在window.onload=function()中也未定义bytessign

Those are the error messages in the console that helped me to identify the errors:这些是帮助我识别错误的控制台中的错误消息:

在此处输入图片说明

在此处输入图片说明

Console logs are also very helpful for troubleshooting.控制台日志对于故障排除也非常有帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM