Hello,
Depending on the selections made using checkboxes I require skip logic to be applied.
How do I determine which checkboxes have been selected?
Check box, how to determine selections
-
- Posts: 18
- Joined: April 2nd, 2015, 4:05 pm
Re: Check box, how to determine selections
This is a question I've had as well. My basic understanding for if they only select one of the options is:
if $ = "b" then
skip to ____;
Since entries are ordered numerically or alphanumerically this would work as well I suppose if you wanted a skip if they selected b and d, "bd". If you have a long list though and want to skip if b was included in any combination you would have to write a lot of contingent answers. ex. "ab" "abc" "abcd" "abcde" ect. If there's an easier way to do this, somebody let us know!
Good luck!
if $ = "b" then
skip to ____;
Since entries are ordered numerically or alphanumerically this would work as well I suppose if you wanted a skip if they selected b and d, "bd". If you have a long list though and want to skip if b was included in any combination you would have to write a lot of contingent answers. ex. "ab" "abc" "abcd" "abcde" ect. If there's an easier way to do this, somebody let us know!
Good luck!
Re: Check box, how to determine selections
Hello,
I have a checkbox based on a valueset that has 9 items
I can use the following to determine which checkboxes have been selected:
if pos("1",choices2) in 1:7 then
skip to choice5;
endif;
if pos("2",choice2) in 1:7 then
skip to choice5;
endif;
I do that for pos 1-7, and that works.
if pos("8",choice2) = 8 then
skip to choice3;
endif;
This works as well.
if pos("9",choice2) = 9 then
skip to choice4;
endif;
That doesn't work, I am still taken to choice3 (which directly follows the question I am currently in.
Based on your example I just tried
if $ = "None" then
skip to choice4;
endif;
but that didn't work ("None" is the checkbox label).
I have a checkbox based on a valueset that has 9 items
I can use the following to determine which checkboxes have been selected:
if pos("1",choices2) in 1:7 then
skip to choice5;
endif;
if pos("2",choice2) in 1:7 then
skip to choice5;
endif;
I do that for pos 1-7, and that works.
if pos("8",choice2) = 8 then
skip to choice3;
endif;
This works as well.
if pos("9",choice2) = 9 then
skip to choice4;
endif;
That doesn't work, I am still taken to choice3 (which directly follows the question I am currently in.
Based on your example I just tried
if $ = "None" then
skip to choice4;
endif;
but that didn't work ("None" is the checkbox label).
Re: Check box, how to determine selections
Using the pos function is the correct approach however you should just be checking the return value of pos against zero rather than relying on the position to be 1:7 or 9. The checkbox control will place the codes for the options that are checked into a string. So if you have a value set like:
Maize 1
Potato 2
Sorghum 3
Millet 4
Groundnut 5
and the user checks Maize and Millet then the value of the field will be: "14". If they select Sorghum, Millet and Groundnut then it will be "345".
To determine if a particular value is checked you just want to know if that code is present in the field. It doesn't matter what position it is in. If pos returns anything other than zero that means that the code is in the field therefore that value is checked.
So to determine if Millet is checked you would do:
if pos("4", choice2) <> 0 then
...
Maize 1
Potato 2
Sorghum 3
Millet 4
Groundnut 5
and the user checks Maize and Millet then the value of the field will be: "14". If they select Sorghum, Millet and Groundnut then it will be "345".
To determine if a particular value is checked you just want to know if that code is present in the field. It doesn't matter what position it is in. If pos returns anything other than zero that means that the code is in the field therefore that value is checked.
So to determine if Millet is checked you would do:
if pos("4", choice2) <> 0 then
...
Re: Check box, how to determine selections
Hi,
Thanks very much for that explanation.
Thanks very much for that explanation.
-
- Posts: 18
- Joined: April 2nd, 2015, 4:05 pm
Re: Check box, how to determine selections
josh wrote:Using the pos function is the correct approach however you should just be checking the return value of pos against zero rather than relying on the position to be 1:7 or 9. The checkbox control will place the codes for the options that are checked into a string. So if you have a value set like:
Maize 1
Potato 2
Sorghum 3
Millet 4
Groundnut 5
and the user checks Maize and Millet then the value of the field will be: "14". If they select Sorghum, Millet and Groundnut then it will be "345".
To determine if a particular value is checked you just want to know if that code is present in the field. It doesn't matter what position it is in. If pos returns anything other than zero that means that the code is in the field therefore that value is checked.
So to determine if Millet is checked you would do:
if pos("4", choice2) <> 0 then
...
Josh, Still working on a code to make this work for me. Referencing the above, what is choice2 and what is it's function in the command?
This is what I have for a multiple choice option value set with up to 10 choices I have listed as a-i, and z for Other. I have a specify other question following that I want skipped if "z" isn't among the answers selected. Is there any help you can give me with this? Thank you, I appreciate it.
if pos("z", choice2) <> 0 then
skip to B8_2;
endif;
-This code is giving me the following errors: ERROR: 'choice2' is not a declared variable or is a misspelled dictionary entry
ERROR: Invalid variable type near line 2 in B8_1 procedure
If I remove the choice2 and leave it at if pos("z") <> 0 then I get the error: ERROR: Invalid function call (number of arguments do not agree) near line 2 in B8_1 procedure
-
- Posts: 133
- Joined: February 11th, 2013, 8:26 am
Re: Check box, how to determine selections
When you define the variable for multiple responses (text variable), define subitems as numeric variables and ask if those numeric variabes have the response you want.
-
- Posts: 18
- Joined: April 2nd, 2015, 4:05 pm
Re: Check box, how to determine selections
I am not sure that I understand. Are you talking about defining the variables (potential response options) in the dictionary? Could you give an example? I typically use letters when I have a large value set that I want to make multiple response options. Thanks!
-
- Posts: 18
- Joined: April 2nd, 2015, 4:05 pm
Re: Check box, how to determine selections
Hi Josh or others that may be able to shed some light on this for me. I think it's been explained pretty well above but here it is again.
I had this question for a previous survey I was working on and never quite figured it out. I'm looking at a question with a list of options asking them to choose all that apply. One of those is "Other specify". After this question there is another which asks them to specify what "other" thing they were referring to. But I only need this question to not be skipped if one of their prior selections was "Other specify".
What I was doing was making it so that if they only chose "Other specify" then it would work, if $ <> "z" then.... skip to. But what I really need is to ask that question if "z" -Other (I tend to use letters for multiple choice questions as they can often be long lists) is among any of the many combinations they could have selected.
Earlier in the thread helped me get on the right path but i'm struggling to make it finally work. If you had some time I would really appreciate your help explaining this one.
Thank you! And thanks again for being so much help in the past, all of you! This is a lifesaver!
I had this question for a previous survey I was working on and never quite figured it out. I'm looking at a question with a list of options asking them to choose all that apply. One of those is "Other specify". After this question there is another which asks them to specify what "other" thing they were referring to. But I only need this question to not be skipped if one of their prior selections was "Other specify".
What I was doing was making it so that if they only chose "Other specify" then it would work, if $ <> "z" then.... skip to. But what I really need is to ask that question if "z" -Other (I tend to use letters for multiple choice questions as they can often be long lists) is among any of the many combinations they could have selected.
Earlier in the thread helped me get on the right path but i'm struggling to make it finally work. If you had some time I would really appreciate your help explaining this one.
Thank you! And thanks again for being so much help in the past, all of you! This is a lifesaver!
Re: Check box, how to determine selections
If you are using checkboxes and you want to see if a particular item in a checkbox is selected then you need to use the pos function to see if the letter associated with that item is in the string value of the field.
As an example say you have a variable LANGUAGES with the following value set:
So to determine if an option was selected you need to see if the letter associated with that option is included in the string. If "A" is in the string that means that English was selected, if "B" is in the string then French was selected, if "C" is in the string then Spanish was selected... Note that it doesn't matter where in the string the letter is, just that the letter is there. If Spanish is selected it might be the first letter ("CDE") or it might be the last ("ABC") depending on what other options are selected with it.
In CSPro logic to determine if the letter is in the string you can use the function pos(). It returns the position of a letter in a string or zero if the letter is not there. So pos("A", "Apple") will be 1, pos("e", "Apple") will be 5 and pos("Q", "Apple") will be zero. Note that as mentioned we don't care about the actual position of the letter, we just care whether or not it is present i.e. whether or not pos() returns zero.
In CSPro logic that translates to:
1.LANGUAGES
2. LANGUAGE_OTHER
3.MARITAL_STATUS
If other is NOT picked in LANGUAGES then we skip to MARITAL_STATUS so that the interviewer doesn't enter LANGUAGE_OTHER.
Putting it all together to determine if the interviewer did NOT check Other (code "E") in the LANGUAGES field and then skip over LANGAUAGE_OTHER you would do:
As an example say you have a variable LANGUAGES with the following value set:
- English - A
- French - B
- Spanish - C
- Mandarin - D
- Other (specify) - E
So to determine if an option was selected you need to see if the letter associated with that option is included in the string. If "A" is in the string that means that English was selected, if "B" is in the string then French was selected, if "C" is in the string then Spanish was selected... Note that it doesn't matter where in the string the letter is, just that the letter is there. If Spanish is selected it might be the first letter ("CDE") or it might be the last ("ABC") depending on what other options are selected with it.
In CSPro logic to determine if the letter is in the string you can use the function pos(). It returns the position of a letter in a string or zero if the letter is not there. So pos("A", "Apple") will be 1, pos("e", "Apple") will be 5 and pos("Q", "Apple") will be zero. Note that as mentioned we don't care about the actual position of the letter, we just care whether or not it is present i.e. whether or not pos() returns zero.
In CSPro logic that translates to:
if pos("E", LANGUAGES) <> 0 then
// other was selected
endif;
or// other was selected
endif;
if pos("E", LANGUAGES) = 0 then
// other was NOT selected
endif;
Building on the above, say that if the user picks Other (code "E") then we want them to enter the name of the other language in the field LANGUAGE_OTHER which directly follows the field LANGUAGES on the form. If they don't pick other then we want to skip over the LANGUAGE_OTHER field to the following field. In this example lets say the next field is MARITAL_STATUS. So on the form the fields are in the following order: // other was NOT selected
endif;
1.LANGUAGES
2. LANGUAGE_OTHER
3.MARITAL_STATUS
If other is NOT picked in LANGUAGES then we skip to MARITAL_STATUS so that the interviewer doesn't enter LANGUAGE_OTHER.
Putting it all together to determine if the interviewer did NOT check Other (code "E") in the LANGUAGES field and then skip over LANGAUAGE_OTHER you would do:
if pos("E", LANGUAGES) = 0 then
// "Other" was not chosen - skip over the other specify field to the field that follows it (MARITAL_STATUS)
skip to MARTIAL_STATUS;
endif;
// "Other" was not chosen - skip over the other specify field to the field that follows it (MARITAL_STATUS)
skip to MARTIAL_STATUS;
endif;