Connect Check Box to Database

How do you connect a check box to a data base?

Probably you missed the fact that when checkbox is added on page, it’s a group contains actual checkbox and text (for description)
Select checkbox in the groul - there is connect panel and you can connect this to boolean value

Many thanks, that fixed it!

Hello @mikhail. Do you know how could you connect the boolean value to a custom value e.g if selected = a certain image goes onto the database?

Hey! You won’t be able to that without coding, but you can achieve this with a bit of code.

Basically, you just need to set the Value on checkbox and before the data is submitted just grab that value: https://www.wix.com/code/reference/$w.Checkbox.html#value

@Adas, would you put that check in a before insert hook? If so, how do you reference the checkbox specifically? Seems like the “$w(`#checkbox1)” referencing doesn’t work in a hook?

You don’t need hooks for that. Basically, you need to check what’s the state of the checkbox, and based on that assign a new value before data is submitted.

This could help you to get started:

$w.onReady(function () {
    $w("#dataset1").onReady( () => {
        $w("#dataset1").onBeforeSave(() => {
 let checkboxValue = $w("#checkbox1").checked ? "True" : "False"
            $w("#dataset1").setFieldValue("data", checkboxValue)
        })
    })
})

Learn more about the methods user here:

Thank you, this helps!

Hello there ! is someone can help me how to Add a checkbox in the checkout which requires customers to agree to your store policies before placing orders. i m trying but it not works .i m trying since 2 days --wix information is not helpfull may it needs some code .is possible some one help me to fix it :frowning:

Hello, I need help connecting my checkboxes to the database. I cannot for the life of me figure out how to do the get value code once the box is checked. Any help would be great! If you respond with some code to get me started as well, that’d be fantastic

Hey! You need make sure you see Properties Panel (Tools > Developer Tools > Properties Panel). Then, select a checkbox and define a function for “onChange” in the Properties Panel. It will generate a function that’s going to be called when checkbox value is changed.

Hi Franklin,
how did you manage to overcome this problem? I am having the same struggle, so I would appreciate a lot if you could give me insights here

Best
Oliver

@devtextileskft have you tried hiding the submit button on load and making a code to show the submit button only after The checkbox is checked? You could then make it hide the submit button again if they uncheck the box.

@adas-bradauskas We should be able to connect a checkbox to a database collection in the exact same way we generate options for a drop down box by connecting it to a database collection. Is this possible? Is it a requested feature already? Or is there a way to achieve this through code?