Firstly note that the checkbox group lets the user choose more than just the one option, so your setup allows the user to choose more than just the one checkbox and submit their answers without any error.
If you want to have just the one answer only, the easiest way is to just use single checkboxes and then you have two options:
-
Add an onClick event for each checkbox, simply set the other three to disable so that they are greyed out;
-
Add a onChange event loop that runs for all checkboxes so that when one is ticked, the others get unticked.
You can find previous posts for this along with code samples if you use the search option in this forum.
As for the values of each checkbox group, if you simply follow the code example for checkbox group and just add ‘let myvalue =…’ in or after the pages onReady function, then you won’t get any value returned in the dev console when you test it in preview mode as it will have run when the page has loaded.
The same with if you have just also added the console log command after the let lines, you can’t get any values returned if you do it with or after the page onReady function.
To get a value in the dev console in the preview mode, then you need to have an event happen for each checkbox group to return a value for you.
This can either be an onChange event for each checkbox group or an onClick event on a simple submit button.
So on each onChange event you would add the console log line for that specific checkbox or you add them all for the onClick event.
Then when the user chooses an option in the checkbox group, with an onChange event the value is added immediately, whereas with the onClick it will only return values when you click on the submit button.
Whether you use an onChange or onClick event on your page, you will only get a value returned for your let lines after the event happens.
Then you can use your keywords for the let lines as you wish in your code.
Finally, remember that the values from checkbox groups are returned in an array, so you will still get an array return of [‘value1’] even if the user is just able to choose the one option.
If you switch to the single checkbox option, then you will just get the one value returned from whatever checkbox the user has chosen.