Search code examples
htmlgoogle-apps-scriptonchangesidebareventtrigger

Can't trigger html-event from Google Apps Script sidebar


I have a Google Apps Script in a Spreadsheet where a html-sidebar contains a select-tagg.

I can't get the onchange-event to trigger the setSheet-function.

HTML-code

<select onchange="google.script.run.setSheet(this.value)">
<? for (var i = 0; i < goodSheets.length; i++) { ?>
  <? var gs = goodSheets[i];?>
  <option value="<?= gs ?>" <? if(gs==sheetName){ ?> selected <? } ?> >
    <?= gs ?>
  </option>
<? } ?>
</select>

GS-code

function setSheet(sheetName){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ss.setActiveSheet(ss.getSheetName(sheetName));
}

Solution

  • Thanks, Sandy Good! F12 showed that getSheetByName was misspelled. Was some delay but finally it worked with the line: SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).activate();