form-to-google-sheets icon indicating copy to clipboard operation
form-to-google-sheets copied to clipboard

Using checkboxes - only the first selected option appears

Open riadina opened this issue 6 years ago • 7 comments

Hi everyone! I'm very new to programming so please forgive me if this obvious, but how do I get all checked boxes to show up on the sheet if I use a group of checkboxes? They all use the same name, and I was hoping to get all checked boxes to appear in one cell, perhaps separated by a comma the way google forms do. But when I try, only the first option selected appears in that cell.

Help will be very much appreciated - thank you so much!

riadina avatar Nov 09 '18 23:11 riadina

I'm having this same issue. Also happens when multiple form elements have the same 'name'.

rodriguesk avatar Aug 12 '19 08:08 rodriguesk

Same here..

Leo-Bieling avatar Aug 13 '19 11:08 Leo-Bieling

same here

ashwinbalaji0811 avatar Sep 21 '20 19:09 ashwinbalaji0811

I got the solution for this trouble!! use different name for different check boxes to collect the data. and add those to the sheets' fields!! and it works just fine

ashwinbalaji0811 avatar Sep 21 '20 19:09 ashwinbalaji0811

#39 pull request has been requested!! Waiting for the Author to take action on these

ashwinbalaji0811 avatar Sep 24 '20 04:09 ashwinbalaji0811

The way I worked around this was to name my checkbox inputs something different. For example if we were having a contest and wanted to have all of the users names populate on which particular email voted for and have them all grouped into one column. I named my checkbox input fields "contestant" and then named a hidden input text field "contestants" which corresponds with my column in the google sheet. On submit of the form after e.preventDefault(), I just loop through the contestants and push them into an array and then join them with a comma and space afterwards and set that value to the "contestants" input value:

form.addEventListener('submit', e => { e.preventDefault() let contestants = document.querySelectorAll('input[name="contestant"]'); let contestants_string = [] let contestants_input = document.querySelector('input[name="contestants"]'); for(var i = 0; i < contestants.length; i++){ contestants_string.push(contestants[i].value); } contestants_string = contestants_string.join(', '); contestants_input.value = contestants_string; fetch(scriptURL, { method: 'POST', body: new FormData(form)}) .then(response => console.log('Success!', response)) .catch(error => console.error('Error!', error.message)) })

AnthonySpain avatar Oct 11 '21 15:10 AnthonySpain

Anthony

The way I worked around this was to name my checkbox inputs something different. For example if we were having a contest and wanted to have all of the users names populate on which particular email voted for and have them all grouped into one column. I named my checkbox input fields "contestant" and then named a hidden input text field "contestants" which corresponds with my column in the google sheet. On submit of the form after e.preventDefault(), I just loop through the contestants and push them into an array and then join them with a comma and space afterwards and set that value to the "contestants" input value:

form.addEventListener('submit', e => { e.preventDefault() let contestants = document.querySelectorAll('input[name="contestant"]'); let contestants_string = [] let contestants_input = document.querySelector('input[name="contestants"]'); for(var i = 0; i < contestants.length; i++){ contestants_string.push(contestants[i].value); } contestants_string = contestants_string.join(', '); contestants_input.value = contestants_string; fetch(scriptURL, { method: 'POST', body: new FormData(form)}) .then(response => console.log('Success!', response)) .catch(error => console.error('Error!', error.message)) })

@AnthonySpain What do you mean hidden input? Can you send us your whole checkboxes input form? It will help a lot because your code still didn't work in mine. Thank you

edricgalentino avatar Oct 31 '21 03:10 edricgalentino