I\'m working in an sidebar menu in an google sheet, to set some variables that i need in my script.
My script is already working. It is easy, on form submit, it will cre
You can use scriptlets
This allows you to use Apps Script functions within the html
code:
<body>
<select name="Available sheets" onchange="myJsFunction()")>
<? var sheets=spreadsheet.getSheets(); ?>
<? for(var i=0;i<sheets.length;i++) { ?>
<option value=<?=sheets[i].getName()?>> <?= sheets[i].getName()?></option>
<? } ?>
</select>
<script>
function myJsFunction(){
var name=document.getElementsByName("Available sheets")[0].value;
google.script.run.goToSheet(name);
};
</script>
</body>
google.script.run allows you to pass the selected sheet to an Apps Script function.
In the .gs file you then need to define what you want to do within the Apps Script function based on the selected sheet, example:
function goToSheet(selectedSheetName){
Logger.log('The selected sheet is: '+ selectedSheetName);
}
Also, you need to change your line var html = HtmlService.createHtmlOutputFromFile('SideBar')
to
var html = HtmlService.createTemplateFromFile('SideBar').evaluate()
to allow the script to evaluate the content of the scriptlets.