I have tried several things, but decided to finally ask for help with this. I am using a Google Scripts UI form like the one found with the example to insert new rows into a Sheet. After the submit button is pressed each time, I would like a success/confirmation message to show the row data after it has been inserted. I would like for the message to be updated each time a new record is inserted.
Updating the div content is pretty simple, in itself.
<script>
function formSubmit() {
google.script.run.getValuesFromForm(document.forms[0]);
var SuccessMessage = "my new content" ; //a function to pull last inserted row perhaps, here?
document.getElementById('mydiv').innerHTML = SuccessMessage;
}
</script>
<div id="mydiv" class="mydiv">mydiv</div>
This function retrieves the values of the last row. I don't know how to get those values to appear inside the designated div.
function myFunction() {
var s = SpreadsheetApp.getActiveSpreadsheet();
var sheet = s.getSheetByName("DATA");
var sheet_last_row = sheet.getLastRow();
var range = sheet.getRange(sheet_last_row, 1, 1, 3);
values = range.getValues();
Logger.log(values);
return values;
}
Placing document.getElementById("mydiv").innerHTML = "New Content";
inside the form submit function updates the div contents. I just need to figure out how to get the function to run that retrieves the values of the new row.
ETA: I updated the Example with code found in another post, that displays the last row of the Sheet. What I need to figure out now is how to have that update each time the submit button is pressed and a new row inserted.