-
Notifications
You must be signed in to change notification settings - Fork 0
/
Google-Apps-Script-Multiple-Dropdown-Select.html
45 lines (39 loc) · 1.4 KB
/
Google-Apps-Script-Multiple-Dropdown-Select.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<div id="checkboxes"></div>
<button onclick="submit()">Submit</button>
<script>
// Load items from the server-side function getItems
google.script.run.withSuccessHandler(function(items) {
var container = document.getElementById('checkboxes');
items.forEach(function(item) {
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = item;
checkbox.value = item;
var label = document.createElement('label');
label.htmlFor = item;
label.appendChild(document.createTextNode(item));
container.appendChild(checkbox);
container.appendChild(label);
container.appendChild(document.createElement('br'));
});
}).getItems();
function submit() {
var selectedItems = [];
var checkboxes = document.getElementById('checkboxes').querySelectorAll('input[type=checkbox]:checked');
checkboxes.forEach(function(checkbox) {
selectedItems.push(checkbox.value);
});
// Write the selected items back to the sheet
google.script.run.writeToSheet(selectedItems);
// Optionally close the sidebar
google.script.host.close();
}
</script>
</body>
</html>