【发布时间】:2020-02-07 22:27:13
【问题描述】:
我正在使用脚本将 HTML 表单中的数据输入到 Google 表格中。有没有办法可以修改(或添加其他内容),以便我的复选框字段将作为列表输入到我的 Google 表格中,以逗号分隔?
因此,使用下面的表格,如果选中所有框,我希望 Google 表格中的“时间”单元格列出上午 9 点、上午 10 点、上午 11 点。现在,它只显示第一个选中的框的值。
表格示例:
<form>
<input type="checkbox" name="time" value="9am">
<label for="time">9:00am</label><br>
<input type="checkbox" name="time" value="10am">
<label for="time">10:00am</label><br>
<input type="checkbox" name="time" value="11am">
<label for="time">11:00am</label><br>
<button type="submit">Submit times</button>
</form>
脚本(来自https://github.com/jamiewilson/form-to-google-sheets):
<script>
const scriptURL = 'https://script.google.com/macros/s/XXXX/exec'
const form = document.forms['submit-to-google-sheet']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => console.log('Success!', response))
.catch(error => console.error('Error!', error.message))
})
</script>
【问题讨论】:
-
我的回答是否向您展示了您想要的结果?你能告诉我吗?这对我学习也很有用。如果这可行,与您有相同问题的其他人也可以将您的问题作为可以解决的问题。如果您对我的回答有疑问,我深表歉意。到时候,可以问一下你现在的情况吗?我想学习解决你的问题。
标签: javascript html forms google-apps-script checkbox