I am sending some text
- from the server to HTML side
- retrieving it on the HTML side via onload
- trying to send it back via a google.script.run call and display on console.log
steps 1. and 2. work fine. I am not able see the information on the server side. here is the code.
script sending the information:
function sendItem() {
var form = HtmlService.createHtmlOutputFromFile('test');
var data = "sometext";
var strAppend = "<div id='id_for_div' style='display:none;'>" + data + "</div>";
form.append(strAppend);
var ui = SpreadsheetApp.getUi();
ui.showSidebar(form);
}
HTML form receiving the information
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function getDataForHtml() {
var id = "id_for_div";
var action = document.getElementById(id).innerHTML;
var element = document.getElementById("myid");
element.innerHTML = action;
}
</script>
</head>
<body onload="getDataForHtml();">
<div>
<br><p id="myid">some text</p> <!-- verifying information in myId -->
<button onclick="sendResponse()">send response</button>
</div>
</body>
</html>
<script>
function sendResponse(action){
var action = document.getElementById("myid").value;
google.script.run.receiveItem();
}
</script>
script receiving information from HTML
function receiveItem(sometext) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
sheet.getRange(10,2).setValue(sometext);
}