Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using checkboxes - only the first selected option appears #12

Open
riadina opened this issue Nov 9, 2018 · 7 comments
Open

Using checkboxes - only the first selected option appears #12

riadina opened this issue Nov 9, 2018 · 7 comments

Comments

@riadina
Copy link

riadina commented Nov 9, 2018

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!

@rodriguesk
Copy link

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

@Leo-Bieling
Copy link

Same here..

@ashwinbalaji0811
Copy link

same here

@ashwinbalaji0811
Copy link

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

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

@AnthonySpain
Copy link

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

@edricgalentino
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants