Google应用HTML表单 - 记录和刷新表单变量

时间:2017-10-06 17:38:33

标签: javascript html google-apps-script

我使用google的html webapp服务努力使用自定义高尔夫笔画HTML表单。目标是在单击按钮后使用新的笔划/孔编号动态刷新表单。最终,它将在谷歌电子表格中记录每个笔画

在点击下一个镜头或下一个洞后,我无法弄清楚如何刷新表格并使用新的笔画/孔号重建html文件。到目前为止,我的代码很粗糙,因为我只是在破解我的方式。

code.gs

function doGet(){
return HtmlService.createHtmlOutputFromFile('Index');
}

function doPost(){
Logger.log("Posted");
}

//hardcoded for testing, will start at 1 for each at beginning of round
var Hole = 11;
var Shot = 22;
var HoleShot = 3;
var DataArr = [Shot, Hole, HoleShot]

function Test() {
Hole++;
Logger.log(DataArr[2]);
Logger.log(HoleShot);
}

function HoleRead() {
return Hole;
 }

function ShotRead() {
return Shot;

}
function HoleShotRead() {
return HoleShot;
}

function NextShot() {
//button function to add 1 to total shots and hole shot, but stay on same hole
//then refresh/clear the form and show the new shot number
Shot++;
HoleShot++;
Logger.log(HoleShot);
ShotToSheet();
//refresh or call NEXT html
return HtmlService.createHtmlOutputFromFile('NEXT');
}

function NextHole() {
//add +1 to hole and total shots but reset hole shot back to 1
//then refresh/clear the form and show the new shot/Hole number
}

function Complete() {

}

function ShotToSheet() {
//records teh 3 variables plus date to a row in a google spreadsheet

}

//builds an Input Spreadsheet if one doesnt exist
function SheetExist() {
    var my_ss = "HTML To Sheet Test";
    var my_sheet = "Input";
    var files = DriveApp.getFilesByName(my_ss);
    var file = !files.hasNext() ? SpreadsheetApp.create(my_ss) : files.next();
    var ss = SpreadsheetApp.openById(file.getId())
    try {
        ss.setActiveSheet(ss.getSheetByName(my_sheet));
    } catch (e) {
        ss.insertSheet(my_sheet);
      //[TO DO]add headers if first time creating Input Sheet
    }
  Logger.log(my_ss + " " + my_sheet);
  //[TO DO]maybe return IDs or names to be used later
}

HTML

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>

  <body>

    <form id="ShotForm">
    <br>
<span id="TotShot"></span>    
<span id="Hole"></span> 
<span id="HoleShot"></span>

 <fieldset id = "ClubData">Club <br>

    <input type="radio" name="Club" id="D" onclick = "ClubClick(this.value);" value="D">
    <label for="D">D</label><br>
    <input type="radio" name="Club" id="5i" onclick = "ClubClick(this.value);" value="5i">
    <label for="5i">5i</label><br>
    <input type="radio" name="Club" id="58" onclick = "ClubClick(this.value);" value="58">
    <label for="58">58</label><br>
    <input type="radio" name="Club" id="P" onclick = "ClubClick(this.value);" value="P">
    <label for="P">P</label><br>    
     <br>

    Type <br> 
    <input type="radio" name="Type" id="Tee Shot" onclick = "TypeClick(this.value);" value="Tee Shot">
     <label for="Tee Shot">Tee Shot</label><br>
    <input type="radio" name="Type" id="Fairway" onclick = "TypeClick(this.value);" value="Fairway">
    <label for="Fairway">Fairway</label><br>
    <input type="radio" name="Type" id="Rough" onclick = "TypeClick(this.value);" value="Rough">
    <label for="Rough">Rough</label><br>
    <input type="radio" name="Type" id="Green" onclick = "TypeClick(this.value);" value="Green">
     <label for="Green">Green</label><br>

    <br> 
   Distance <br>
    <input type="number" name="Distance" onchange = "DistanceEdit(this.value);" min="1" max="1000">
      </fieldset>     

<span id="TotShot2"></span>    
<span id="Hole2"></span> 
<span id="HoleShot2"></span>
 will be recorded as:<br>
<span id="Choice1">Club</span> - 
<span id="Choice2">Type</span> -
<span id="Choice3">Distance</span>

 <br> <br>
 <input type="submit" name="NextShotButt" onclick = "NextShot();"value="Next Shot"><br> <br>
 <input type="button" name="NextHoleButt" onclick = "NextHole();" value="Next Hole"><br> <br>
 <input type="button" name="Complete" onclick = "Complete();" value="Complete">
   </form>
  </body>

0 个答案:

没有答案