I have some code that works but I need to bring in a form value instead of my hard coded text. I am using Google Apps Script's HTML Service and a Google Spreadsheet to try to accomplish the goal. I am hoping an expert would be kind enough to share a solution.
My index.html
<div id="inputDiv">
<form id="inputForm" onsubmit="fncWriteInputData()">
<label>Name: </label> <br />
<input type="text" tabindex="1" id="idFirstInput" class="inptFld" placeholder="Add a name" required><br />
<label>Number:</label> <br />
<input type="text" tabindex="2" id="idSecondInput" class="inptFld" placeholder="Employee number" required><br />
<br />
<input type="submit" tabindex="3" id="btnSubmitInput" value="Click To Submit">
</form>
</div>
<div>
<hr>
<? var data = getData(); ?>
<table>
<? for (var i = 0; i < data.length; i++) { ?>
<tr>
<? for (var j = 0; j < data[i].length; j++) { ?>
<td><?= data[i][j] ?></td>
<? } ?>
</tr>
<? } ?>
</table>
</div>
<script>
fncWriteInputData=function(){
var value = (inputForm.idFirstInput)
console.log("fncWriteInputData ran");
google.script.run
.fncRunAppScript(); //Runs server side .gs function
}
</script>
My code.gs looks like
var submissioSSKey = '1N6uShSxHwhFYrfTDhJyp8ohCHpvElVAOtuGdQv3kt8k';
function doGet() {
return HtmlService
.createTemplateFromFile('index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function getData() {
return SpreadsheetApp
.openById(submissioSSKey)
.getActiveSheet()
.getDataRange()
.getValues();
}
function fncRunAppScript(inputForm){
var ss = SpreadsheetApp.openById(submissioSSKey);
var sheet = ss.getActiveSheet();
var lastRow = ss.getLastRow();
var cell = sheet.getRange(lastRow+1, 1, 1,2);
var value= "Frank"; //this works but I need the value in the text box
// var value = value.idFirstInput;//nogo
// var value= index.html.inputForm.idFirstInput.getValue();//nogo
var value2= "123";
// cell.setValues([[value1a,value2a]]);//this one works
cell.setValues([[value,value2]]);//this one works
}
If I rem "//"
var value= "Frank"; //this works but I need the value in the text box
And try something like
var value= index.html.inputForm.idFirstInput.getValue();
I do not get the form value
I am hoping someone can show me the way to grab a value from an input form so that it can be inserted into the spreadsheet.