Query checkboxes

Hello everyone

I have questions on a form with various possible answers.

One question has four possible answers that can be answered with checkboxes. Answers 2 and 4 are correct.

I would now like to set a "true" in the "Quest_1_result" field if the question is answered correctly.

However, the following code does not do what I had in mind.

Can anyone help me with this?

Many thanks
Andreas

function Ques1() {
    if (fd.field('AnswQuest_1_1').value == false || fd.field('AnswQuest_1_2').value == true || fd.field('AnswQuest_1_3').value == false || fd.field('AnswQuest_1_4').value == true) {
        fd.field('Quest_1_result').value = true; 
    } else {
        fd.field('Quest_1_result').value = false;
    }

}

Hello @Andreas_Sch,

What is the type of field? Is it a Choice field that allows multiple selections?

Hi Margarita
Thank you for the quick response.
No, they are single fields of the type Boolean that capture the state whether the box was selected or not.

function Ques1() {
    if (fd.field('AnswQuest_1_1').value == '' && fd.field('AnswQuest_1_2').value == '1' && fd.field('AnswQuest_1_3').value == '' && fd.field('AnswQuest_1_4').value == '1') {
        fd.field('Quest_1_result0').value = '1'; 
    } else {
        fd.field('Quest_1_result0').value = '0';
    }

}

I made some improvements yesterday, now it seems to fit.

Or can I still improve this?

Thx
Andreas

@Andreas_Sch,

For the Boolean field type, I'd updated the code like so:

 function Ques1() {
        if (!fd.field('AnswQuest_1_1').value && fd.field('AnswQuest_1_2').value && !fd.field('AnswQuest_1_3').value && fd.field('AnswQuest_1_4').value) {
            fd.field('Quest_1_result0').value = true; 
        } else {
            fd.field('Quest_1_result0').value = false;
        }
}
1 Like

Thank you very much for your prompt support.

have a great day
Andreas

1 Like