top of page

Checkboxes: Set Value to Single Field on Button On Click 

Test it out:

Monday

Tuesday

Wednesday

Thursday

Submit

After you create your checkboxes, activate the 'on click' event in the properties panel:

For your button, activate the 'onClick' event in the properties panel:

The code on the page for the example above:

$w.onReady(function () {
    $w("#checkbox1").value = '';  //by having ' ' it makes the value equal 'nothing' when the page is loaded
    $w("#checkbox2").value = '';
    $w("#checkbox3").value = '';
    $w("#checkbox4").value = '';

});

​

export function checkbox1_click() {
    dayMonday();
}

export function checkbox2_click() {
    dayTuesday();
}

export function checkbox3_click() {
    dayWednesday();
}

export function checkbox4_click() {
    dayThursday();

 

//because the page started with all the value to equal 'nothing', now we will set the values to equal the real value

​

function dayMonday() {
            if ($w("#checkbox1").value === '') {
            $w("#checkbox1").value = 'monday';    
            }
            else {
                $w("#checkbox1").value = '';
            }
}

function dayTuesday() {
            if ($w("#checkbox2").value === '') {
            $w("#checkbox2").value = 'tuesday';    
            }
            else {
                $w("#checkbox2").value = '';
            }
}

function dayWednesday() {
            if ($w("#checkbox3").value === '') {
            $w("#checkbox3").value = 'wednesday';    
            }
            else {
                $w("#checkbox3").value = '';
            }
}

function dayThursday() {
            if ($w("#checkbox4").value === '') {
            $w("#checkbox4").value = 'thursday';    
            }
            else {
                $w("#checkbox4").value = '';
            }
}

function valueCombine() {
    let checkedValue = $w("#checkbox1").value + " " + $w("#checkbox2").value + " " + $w("#checkbox3").value + " " + $w("#checkbox4").value;
    $w("#testValue").value = checkedValue;
}


export function submitButton_click() {
    valueCombine();
}

bottom of page