Reputation: 68
I am working on a script that requires html form data to be inputted to a web app, I then want to be able to process that form data and put it on a google sheet. The thing is I can't seem to do that. Here is my code:
Index.html
<form id="Form" onsubmit="event.preventDefault();
google.script.run.getData(this)">
<input type="text" name="firstname">
<input type="submit">
</form>
Code.gs
function getData(data) {
var sheet= SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Logs');
sheet.getCurrentCell().setValue(data.name);
}
What am I doing wrong?
Upvotes: 0
Views: 869
Reputation: 5953
The issue in your code is that your your data
doesn't have a name
member/key. Hence, you are writing a null
value in your current cell which will result to an empty cell value.
function getData(data) {
Logger.log(data)
Logger.log(data.name)
var sheet= SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Logs');
sheet.getCurrentCell().setValue(data.firstname);
}
A1
Upvotes: 1
Reputation: 1429
Check the documentation for a practical example.
In your case, you have a form which you submit. In that case the form does not know which is the active cell. Therefore you should replace getCurrentCell()
with getRange()
or appendRow()
Reference
appendRow([formObject.name])
getLastRow()
, you can then set the value in itUpvotes: 0