Assign Database field value to radio button

I am trying to assign a field value from a database to a radioGroup inside a repeater, and have the selected radioGroup value submitting to a writable form database.

Right now I am executing the submit in code using wixdata.insert, I have also tried with .save(). In every event a new entry is created, but the entries come up blank…even though a radio button was selected.

Right now I am setting the options of radioGroup1 to be the text #planInternet.
I have #planInternet connected to the database that is feeding the repeater…and so it is that value that I want to submit.

If I connect the submit button not using code…I get an entry equivalent to whatever is in the text box inside the editor. In this instance…“Plan Internet” is submitted.

Done using code…nothing gets submitted, but a new entry is successfully made.

I am not sure if I am using setFieldValue correctly…but I believe it hold the key to getting the database value over and into the submission dataset.


Pic and current code below…

import wixData from ‘wix-data’;

//TV Internet Repeater Radio Group//

$w.onReady( function () {

$w("#repeater1").onItemReady( (itemData, index) => { 

    $w("#radioGroup1").options = [ 

{“label”: “”, “value”: $w(“#planInternet”).text},


$w(“#radioGroup1”).onClick( (event, $w) => {
let $item = $
$item(“#radioGroup1”).selectedIndex = 0;
} );

export function resetRadioButtons () {
$w(‘#radioGroup1’).selectedIndex = undefined;

$w.onReady( function () {

let tvinternet
let electric;
let insurance;
let movers;
let security;


export function submit_click(event, $w) {

let toInsert = {
‘tvInternet’ : $w(‘#radioGroup1’).value,
‘electric’ : $w(‘#radioGroup2’).value,
‘insurance’ : $w(‘#radioGroup3’).value,
‘movers’ : $w(‘#radioGroup4’).value,
‘security’ : $w(‘#radioGroup5’).value,


wixData.insert(“UtilitiesSubmission”, toInsert)



function resetForm() {
$w(‘#radioGroup1’).value = ‘’

Have a read of radio button groups here.$w.RadioButtonGroup.html

Each radio button in the group needs a label that the user sees and also a value that gets added to your dataset.

This is explained on the first link in the example box.$w.RadioButtonGroup.html#value

Also, your onReady page function should be at top of page and not in the middle of your code after export functions.

Have read here too.

Radio Buttons
Radio Buttons allow users to select one of a predefined set of options.
Radio buttons have a label (text displayed on your page) and a value (data stored in your collection).

I have read all the references you are siting. My issue is that the database field value is not passing from the text element to the radiogroup value. I am only getting the text itself…and even then it submits a blank entry.

Is there a way to directly assign a database field value to a radiogroup option?

On your repeater you need to have the actual radio group set as the label and the value for the dataset field is given from that user choice and that needs to be set to the dataset field.

You will obviously get it without using code as you are not using the radio group value and are simply connecting the text element’s value to the dataset field instead.

As it states in the API Reference.
Radio button groups are used for selecting one of a number of options. Radio button groups consist of a list of options . Each option contains a label, which is what the user sees, and a value, which is what is used in code and stored in you collections.

You can set the labels and values through code of a radio group.$w.RadioButtonGroup.html#options

Set the list of options for a radio button group

$w("#myRadioGroup").options = [
  {"label": "Who's on first!", "value": "first"},
  {"label": "What's on second", "value": "second"},
  {"label": "I Don't Know is on third", "value": "third"}

You might find it easier to simply just us a single checkbox and set the value for it and then check to see if it is checked or not etc.$w.Checkbox.html$w.Checkbox.html#checked$w.Checkbox.html#value

How can I assign the field title of a radio button with wix code?

1 Like