Javascript 将逗号列表中的多个复选框选择张贴到Google工作表

Javascript 将逗号列表中的多个复选框选择张贴到Google工作表,javascript,html,forms,google-apps-script,checkbox,Javascript,Html,Forms,Google Apps Script,Checkbox,我正在使用一个脚本将HTML表单中的数据输入到Google工作表中。有没有办法修改(或添加其他内容),使我的复选框字段作为列表输入到我的Google工作表中,并用逗号分隔 因此,在下面的表格中,如果选中了所有框,我希望谷歌表单中的“时间”单元格列出上午9点、上午10点和上午11点。现在,它只显示选中的第一个框的值 表单示例: <form> <input type="checkbox" name="time" value="9am"> <label for="time

我正在使用一个脚本将HTML表单中的数据输入到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>
<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>

上午9:00
上午10:00
上午11:00
提交次数
脚本(来自):

<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>
<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>

常量脚本URL=https://script.google.com/macros/s/XXXX/exec'
const form=document.forms['submit-to-google-sheet']
form.addEventListener('submit',e=>{
e、 预防默认值()
fetch(scriptURL,{method:'POST',body:newformdata(form)})
.then(response=>console.log('Success!',response))
.catch(error=>console.error('error!',error.message))
})
  • 您希望将复选框的值放入电子表格,如
    9am、10am、11am
  • 在您当前的情况下,只会放入第一个复选框的值
  • 您正在使用的Google应用程序脚本
  • 在电子表格中,
    时间戳
    时间
    的标题行被放置到要放置值的电子表格的第一行
如果我的理解是正确的,那么这个答案呢?请把这看作是几个可能的答案之一

修改点:
  • 在HTML中,复选框使用相同的名称。时间到了。在这种情况下,您可以在Google端通过
    e.parameters[“time”]
    检索值
修改脚本: 请修改如下

发件人: 致:
  • 在这种情况下,如果标题行中不存在
    time
    ,则不会输入值。请小心这个
注:
  • 修改Web应用脚本时,请将Web应用重新部署为新版本。这样,最新的脚本就会反映到Web应用程序中。请注意这一点。
参考:

不幸的是,我看不到您当前的谷歌应用程序脚本和电子表格。因此,如果上述修改未能解决您的问题,我深表歉意。当时,为了正确理解您的情况,您能否提供包含整个脚本的示例电子表格?通过这个,我想检查一下。

我的回答是否显示了您想要的结果?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。如果你对我的回答还有疑问,我道歉。那时候,我可以问一下你目前的情况吗?我想学习来解决你的问题。