I added a sidebar to a spreadsheet and I am able to pass variables from the sidebar to the sheet (using google.script.run). How do I pass values back from the spreadsheet to the sidebar, modifying the sidebar content?
EDIT: Adding my code. Basically I enter a number in the sidebar, find its row position in the spreadsheet, and need to pass that row fields back to the sidebar, to update the divs (#fieldA, fieldB).
Once I get the row number, I just need to add fieldA, fieldB values to a variable , but I don't know how to pass that back to the sidebar.
Spreadsheet
Number FieldA FieldB
111 1a 1b
222 2a 2b
333 3a 3b
index.html
<form>
<input type="text" id="someNumber">
<button type="button" onClick="findNumber()">Find number</button>
</form>
<div id="fieldA"></div>
<div id="fieldB"></div>
<script>
function findNumber(){
var number = document.getElementById("someNumber").value;
google.script.run.findNumber(number);
}
</script>
code.gs
var sheet = SpreadsheetApp.getActiveSheet();
function findNumber(a){
var lastRow = sheet.getLastRow();
var lookRange = sheet.getRange(1, 1, lastRow);
var values = lookRange.getValues();
for (i in values) {
if (values[i] == a) {
var updateRow = 1+ parseInt(i);
Logger.log(values[i] + " is in row " + updateRow);
break;
}
}
}