Page 1 of 1

Depending chekbox

Posted: September 8th, 2016, 7:22 am
by hamouda1987
hello people ,

I have 2 checkbox with the same value in question 1 and question 2.
question 1 : chekbox :1-car1 2- car2 3-car3 4-car4
question 2 : chekbox :1-car1 2- car2 3-car3 4-car4
what i want to do is when i choose for example in the question 1 the answers 1 and 2 , in question 2 i want to see just answers 3 and 4.
It means that the 2 chekbox depends on the 1 chekbox.

Can i do that?

Thank you good people
Kind regards

Re: Depending chekbox

Posted: September 8th, 2016, 12:51 pm
by Gregory Martin
This is nontrivial, but the best way to do this is to use a dynamic valueset. You will construct the valueset, adding each value only after checking if it was selected in the first checkbox value.

See attached for an example of this. The code is below:
PROC CHECKBOX_2

preproc

    
// In this example, there are five checkbox codes in CHECKBOX_1;
    // I will create a dynamic valueset using all but the selections in CHECKBOX_1
    numeric vsCtr = 1;
    
    
do numeric ctr = 1 while ctr <= 5
    
        
string stringCode = edit("9",ctr);
        
        
// only add codes that were not found in CHECKBOX_1
        if pos(stringCode,CHECKBOX_1) = 0 then

            
// add the code, getting the label from CHECKBOX_1 value set
            vsCheckboxCodes(vsCtr) = stringCode;
            vsCheckboxLabels(vsCtr) =
getlabel(CHECKBOX_1,stringCode);
            
inc(vsCtr);
            
        
endif;
    
    
enddo;
    
    
// end the dynamic value set
    vsCheckboxCodes(vsCtr) = "";    

    
// set the dynamic value set for CHECKBOX_2
    setvalueset(CHECKBOX_2,vsCheckboxCodes,vsCheckboxLabels);

Re: Depending chekbox

Posted: November 5th, 2016, 10:29 am
by Laedry
Dear Mr Gregory,

How can I doing it if the labels are in alphabetique