Using element .onclick to tick a checkbox doesn't actually input data into form?

Hi there, i’m creating a form on my site that allows users to click a selection of images, to make a set of choices. My plan is to create individual checkboxes for each image & it’s overlaying container box, to enable this behaviour, before letting them submit. However, on testing this, i’m running into an issue i can’t solve.

My code is really simple - for the container box that overlays an image, to tick the checkbox, it’s as follows, with all other code removed for parsimony.

export function box1_click(event) {

$w( '#A' ).checked =  **true** ; 

With #A being my checkbox. However, when testing this on preview, i’m getting the following problem.

Clicking the ‘image/container box1’ DOES tick the checkbox, as expected. However, when submitting this using a button, the ticked box isn’t registered in my database. However, if i just click the checkbox itself to add a tick to it, not the image, this data IS submitted. Visually, each behaviour is identical, it’s just the former is failing to retain/submit this info. & i need these checkboxes to be hidden for my design.

Before i go any further i need to resolve this, as the entirety of my page’s function depends on it, with everything else behaving 100% as i’d want it to.

Why is this happening, & how do i resolve it?

Thank you :slight_smile:

If I understand correctly, you have your fields connected to a Dataset. In addition to setting the checked state of the checkbox, you will also need to use the setFieldValue() function of the Dataset.

Thank you Yisrael, yes that’s right they’re connected to a dataset.

So in my situation, i’d add something like this to my .onclick ?

$w(“#myDataset”).setFieldValue(“A”, “true”);

I am unsure of what to set the field value part to, despite reading through the documentation. The field’s value is labelled ‘A’ for this checkbox, but it’s still not working with the above code.

If you could please elaborate on what i’m doing wrong i’d really appreciate it.

Your checkbox is connected to a Dataset, and the Dataset is connected to a database collection. What is the field key in the collection that the Dataset is connected to, that corresponds to the checkbox value?

@yisrael-wix Ahhh that’s fixed it. My field key was also ‘A’, but i’d forgotten it was lowercase, not uppercase. Changing it to ‘a’ in the above code has fixed it.

Does this also mean that my use of checkboxes in general is redundant, & that i could input this data without using them at all?

Thanks for your help!