I am making a google site which shows a drop down based on data coming from a Google Sheet. It works.
As next step, I want that when the user select a drop down choice from the list, the value which is selected is written in Google Sheet cell (in the example below, the selected value will be written in Sheet: "Dashboard", cell: B92).
For example, assume that the drop down list has the following values coming from the Sheet: "Item 1", "Item 2", "Item 3".
When the user select "Item 1" from the web site, the script should write "Item 1" in Google sheet cell B92. Similarly, if the user select "Item 2", the script will set "Item 2" in cell B92.
I tried with the code below, but I think something is wrong with:
- fetch in the HTML file
- doPost(e) because I am not sure how to pass the parameter
(I removed the entire code to focus on the pieces which are incorrect. I can add it back if needed)
function doPost(e) {
var ss=SpreadsheetApp.openById('XXXXXXXX');
var sh=ss.getSheetByName('Dashboard');
sh.getRange(92,2).setValues(e.parameter);
}
HTML file:
<script type="text/javascript"> var lastIndex = ""; const url = "https://script.google.com/a/google.com/macros/s/AKfycbxHX7cthji076OrqfY9ZpGa7jNDxKHUMf_ib7Ekmoo0Ir5DQF1Y/exec"; function listQ(){ var e = document.getElementById("sel1"); if(e.selectedIndex > 0){ lastIndex = e.selectedIndex; console.log(lastIndex); fetch(url, { method: "POST" , body: lastIndex }).then(function (response) { return response.json() }).then(function (data) { console.log(data); }) } } document.getElementById("sel1").addEventListener("click",listQ);