9 Replies Latest reply on Jul 6, 2017 1:45 PM by charlesdtilton

    Checkbox calculation

    dbice

      This is probably really simple. I have a checkbox set with 4 values (A, B, C, D), and then a radio button set with values 0 and 1. In order to get the item correct, both C and D have to be selected. I would like for this to automatically score the radio button set with 1 or 0. I typically use simple If statements to auto score, but I'm not sure how to specify that the correct answer is two values, not just one. Could someone tell me the best way to go about this? Thanks!

        • 1. Re: Checkbox calculation
          philmodjunk

          valueCount (FilterValues ( List ( "C" ; "D" ) ; CheckBoxFieldHere ) ) = 2

           

          This will evaluate as 1 if values C and D (and no other values) are selected.

          • 2. Re: Checkbox calculation
            charlesdtilton

            The values checked will be stored in the field as a delimited value with a carriage return as the delimiter.

             

            Something like:

             

            )

                   GetValue( YourField; 3) = "c"

                     or  
                    GetValue( YourField; 3) = "d"
            )

              and

             

            (       GetValue( YourField; 4) = "c"

                      or 

                    GetValue( YourField; 4) = "d"
            )

             

            will evaluate as true if the options are a, b, c, d in that order.  You can then use a if-then statement.  If it evaluates true then set your field to 1.

            • 3. Re: Checkbox calculation
              brucewilson

              Sorry Phil, as you filter out A and B they are not counted, even if checked.

               

              ( valueCount (FilterValues ( List ( "C" ; "D" ) ; CheckBoxFieldHere ) ) = 2 ) AND ( valueCount ( CheckBoxFieldHere )  = 2 )

               

              or alternatively

               

              ( valueCount (FilterValues ( List ( "C" ; "D" ) ; CheckBoxFieldHere ) ) = 2 ) AND ( valueCount (FilterValues ( List ( "A" ; "B" ) ; CheckBoxFieldHere ) ) = 0 )

              • 4. Re: Checkbox calculation
                brucewilson

                Hi Charles,

                 

                The delimited list will look like either

                     c

                     d

                or

                     d

                     c

                So you should be checking values 1 and 2, not 3 and 4.

                You would also need to check that there were no other values in the list (no value 3) as there would be if the list contained

                     c

                     d

                     a

                 

                Bruce.

                • 5. Re: Checkbox calculation
                  brucewilson

                  If [ checkbox = "c¶d" or checkbox = "d¶c" ]

                       Set Field [ radiobutton ; 1 ]

                  Else

                       Set Field [ radiobutton ; 0 ]

                  End If

                  • 6. Re: Checkbox calculation
                    user19752

                    I'm not sure OP didn't write about A and B, but saying "the correct answer is two values" likely they shouldn't be checked...

                     

                    I want to write something like

                     

                    Let ( [

                    correctAnswer = List ( "C" ; "D" ) ;

                    answer = CheckBoxFieldHere ;

                    checkes = ValulistItems ( "" ; ValuelistNameHere )

                    ] ;

                    FilterValues ( checkes ; answer ) = correctAnswer

                    )

                     

                    but List() never be equal to **Values() function they have ending line break!!

                    • 7. Re: Checkbox calculation
                      charlesdtilton

                      Your right Bruce, thanks for catching it.

                      • 8. Re: Checkbox calculation
                        dbice

                        Thanks everyone for all of the feedback! I really appreciate the help.

                         

                        Bruce, I started with your first suggestion because it was the least intimidating

                         

                        ( valueCount (FilterValues ( List ( "C" ; "D" ) ; CheckBoxFieldHere ) ) = 2 ) AND ( valueCount (FilterValues ( List ( "A" ; "B" ) ; CheckBoxFieldHere ) ) = 0 )

                         

                        And really, it works great. Thanks so much! I'm worried about one thing - when I make a selection in the checkbox, it automatically scores the radio button field, which is great. But if I deselect the response options so that the checkboxes are empty, the radio button remains at 0. This usually wouldn't be a big deal, but in this case it makes a difference because I also have a script for a dialog box to come up if the participant scores 3 consecutive zeros.

                         

                        Is there a way to make sure that if the checkboxes are empty, the radio button will also always be empty?

                        • 9. Re: Checkbox calculation
                          charlesdtilton

                          You could do a on object modify trigger to check if the field that is dependent upon the checkboxes is empty then set the field that is dependant upon the radio button to empty also.

                          1 of 1 people found this helpful