# How to automatically check a checkbox connected to dataset

**URL:** <https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 16, 2018, 5:55am UTC](https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740 "2018-05-16T05:55:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew-colan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/matthew-colan/32/993_2.png) [@matthew-colan](https://forum.wixstudio.com/u/matthew-colan)\
**Post date:** [May 16, 2018, 5:55am UTC](https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740/1 "2018-05-16T05:55:31Z")

</div>

I am trying to add a checkbox element and connect it to a dataset that is a boolean field. As soon as I connect the element to the database and I preview, it will not automatically check the field box with a check mark. Can someone tell me how I can load a page that will have a check mark already in the checkbox field that is connected to a dataset? Assume I do not have any coding knowledge. Meaning if there is a coding requirement I need the whole code and not just parts of it. I want this element automatically checked so when I hit a submit button the boolean field is checked in the database.

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [May 17, 2018, 1:00pm UTC](https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740/2 "2018-05-17T13:00:54Z")

</div>

Hi Matthew

You can read about the functionality of [CheckBoxes](https://www.wix.com/code/reference/$w.Checkbox.html) here in the API.  
Anyway, making the checkbox checked by default is pretty easy; Just go to the checkbox settings and mark the option “checked by default” as shown here:

![](https://us1.discourse-cdn.com/wix/original/3X/6/3/63f62578c6baf8b1d315f465eccb93c7f5e20ad0.png)  
It might require you to ungroup the checkbox itself from the text box that comes along when you add it to your editor.

Hope it helps!  
Best of luck.

Doron. 🙂

---

<div class="post-metadata">

**Author:** ![matthew-colan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/matthew-colan/32/993_2.png) [@matthew-colan](https://forum.wixstudio.com/u/matthew-colan)\
**Post date:** [May 17, 2018, 3:17pm UTC](https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740/3 "2018-05-17T15:17:06Z")

</div>

Doron, Thank your for your reply. First, yes I have read about the checkboxes in the API, however, the API assumes that I am a coder or have a baseline knowledge of java. There are not enough examples of each of the API elements for a non-coder to easily figure out what the code is doing. Secondly, I am also very familiar with how to set the value by default within Wix on a checkbox element, however, what I am experiencing is that when I connect the checkbox to a database, it no longer defaults to being checked. It will show as being defaulted in the image you attached to your reply, however, it is not checked when I push this out to a live site.

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [May 23, 2018, 3:11pm UTC](https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740/4 "2018-05-23T15:11:13Z")

</div>

Hi Matthew!

What I would suggest you to do is to add an event to the checkbox (View Properties), ’ [onChange](https://www.wix.com/code/reference/$w.Checkbox.html#onChange) ', and set a condition that will update the data of the boolean field in your collection every time the value of the checkbox is changed.  
The update should happen by one of two options, either through the dataset (if your component is connected by one) and then you should use the [setFieldValue( )](https://www.wix.com/code/reference/wix-dataset.html#setFieldValue) and [save( )](https://www.wix.com/code/reference/wix-dataset.html#save) methods.  
Or simply by [update( )](https://www.wix.com/code/reference/wix-data.html#update) of the database.  
For example, using a dataset (“#dataset1”) - it should look something like that:

```javascript
export function checkbox1_change(event, $w) {
	$w("#dataset1").setFieldValue("BoolTest", $w("#checkbox1").value);
	// "BoolTest" is my example field name for a boolean variable
	$w("#dataset1").save();
}

```

Hope it helps!  
Best of luck.

Doron. 🙂

---

<div class="post-metadata">

**Author:** ![lancemilionariosupor](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lancemilionariosupor](https://forum.wixstudio.com/u/lancemilionariosupor)\
**Post date:** [February 18, 2022, 2:00am UTC](https://forum.wixstudio.com/t/how-to-automatically-check-a-checkbox-connected-to-dataset/42740/5 "2022-02-18T02:00:01Z")

</div>

Very good! it worked!

But how the checkbox can be saved in the database for each user?
