Hi all,
So I have a form with a checkboxGroup in it named checkboxGroup1, checkboxGroup2 and checkboxGroup3 respectively. I've also set the checkbox to required.
![](https://static.wixstatic.com/media/a27d24_3b123cfa20d34a11b75cbc3586e1c98d~mv2.png/v1/fill/w_846,h_523,al_c,q_90,enc_auto/a27d24_3b123cfa20d34a11b75cbc3586e1c98d~mv2.png)
Hence, when I tried to get the value of the selected items as per the docs through
let howDidYouHearAboutUs = $w('#checkboxGroup3').value; // list
let yearOfExam = $w('#checkboxGroup3').value; // list
// expecting ['value', 'value2']
However I am met with a error code of:
Wix code SDK Warning: The value parameter of "checkboxGroup1" that is passed to the value method cannot be set to null or undefined.
I'm struggling to figure out why this is happening and any help would be appreciated.
Thanks!
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.
Hallo,
try to figure out if it is a "type-error" for example: console.log(typeof ............)
and look what you get when you do a "console-log" --->
console.log($w('#checkboxGroup3').value)