I'm using a script to enter data from an HTML form into a Google Sheet. Is there a way I can modify this (or add something else) so that my checkbox fields will be entered into my Google Sheet as a list, separated by commas?
So with the form below, I would want the cell for "time" in Google Sheets to list 9am,10am,11am if all boxes were checked. Right now, it only displays the value of the first box that's checked.
Form example:
<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>
The script (from 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>
Aucun commentaire:
Enregistrer un commentaire