Millisecond Forums

checkboxes.checkboxname.selectedcount

https://forums.millisecond.com/Topic18911.aspx

By Yuxi - 4/14/2016

Dear all,

I met a problem with checkboxes.checkboxname.selectedcount.
There are 18 checkboxes in the task, each with one option. I asked people to select 6 checkboxes from the 18. Then I want to get the values of the selected 6 options. I wrote a script as below. However, logic expression values.checkboxselect == "1" is always wrong in the 6 trials below. 
Does anyone know why? Any help or information will be appreciated! 

<item Newoptions>
/ 1 = "<% values.option1        
             
                 %>"
/ 2 ="<% values.option2        
             
                 %>"
/ 3 = "<% values.option3        
             
                 %>"
/ 4 = "<% values.option4        
             
                 %>"
/ 5 = "<% values.option5        
             
                 %>"
/ 6 = "<% values.option6        
             
                 %>"
/ 7 = "<% values.option7        
             
                 %>"
/ 8 = "<% values.option8        
             
                 %>"
/ 9 = "<% values.option9        
             
                 %>"
/ 10 = "<% values.option10        
             
                 %>"
/ 11 = "<% values.option11        
             
                 %>"
/ 12 = "<% values.option12        
             
                 %>"
/ 13 = "<% values.option13        
             
                 %>"
/ 14 = "<% values.option14        
             
                 %>"
/ 15 = "<% values.option15        
             
                 %>"
/ 16 = "<% values.option16        
             
                 %>"
/ 17 = "<% values.option17        
             
                 %>"
/ 18 = "<% values.option18        
             
                 %>"
</item>
<item selectedcount>
/ 1 = "<%checkboxes.option1.selectedcount%>"
/ 2 = "<%checkboxes.option2.selectedcount%>"
/ 3 = "<%checkboxes.option3.selectedcount%>"
/ 4 = "<%checkboxes.option4.selectedcount%>"
/ 5 = "<%checkboxes.option5.selectedcount%>"
/ 6 = "<%checkboxes.option6.selectedcount%>"
/ 7 = "<%checkboxes.option7.selectedcount%>"
/ 8 = "<%checkboxes.option8.selectedcount%>"
/ 9 = "<%checkboxes.option9.selectedcount%>"
/ 10 = "<%checkboxes.option10.selectedcount%>"
/ 11 = "<%checkboxes.option11.selectedcount%>"
/ 12 = "<%checkboxes.option12.selectedcount%>"
/ 13 = "<%checkboxes.option13.selectedcount%>"
/ 14 = "<%checkboxes.option14.selectedcount%>"
/ 15 = "<%checkboxes.option15.selectedcount%>"
/ 16 = "<%checkboxes.option16.selectedcount%>"
/ 17 = "<%checkboxes.option17.selectedcount%>"
/ 18 = "<%checkboxes.option18.selectedcount%>"
</item>

<trial Newoption1>
/ ontrialbegin = [values.newoptionA = getitem(item.Newoptions,values.shuffleA1)]
/ ontrialbegin = [values.checkboxselect = getitem(item.selectedcount,values.shuffleA1)]
/ ontrialbegin = [if (values.checkboxselect == "1" ) values.newoption1 = values.newoptionA]
/ ontrialend = [values.shuffleA1 = values.shuffleA1 + 1]
/ branch = [if (values.checkboxselect == "1" ) trial.Newoption2 else trial.Newoption1]
/ timeout =1
</trial>

<trial Newoption2>
/ ontrialbegin = [values.newoptionB = getitem(item.Newoptions,values.shuffleA1)]
/ ontrialbegin = [values.checkboxselect = getitem(item.selectedcount,values.shuffleA1)]
/ ontrialbegin = [if (values.checkboxselect== "1" ) values.newoption2=values.newoptionB]
/ ontrialend = [values.shuffleA1 = values.shuffleA1 + 1]
/ branch = [if (values.checkboxselect== "1" ) trial.Newoption3 else trial.Newoption2]
/ timeout = 1
</trial>

<trial Newoption3>
/ ontrialbegin = [values.newoptionC = getitem(item.Newoptions,values.shuffleA1)]
/ ontrialbegin = [values.checkboxselect = getitem(item.selectedcount,values.shuffleA1)]
/ ontrialbegin = [if (values.checkboxselect== "1" ) values.newoption3=values.newoptionC]
/ ontrialend = [values.shuffleA1 = values.shuffleA1 + 1]
/ branch = [if (values.checkboxselect== "1" ) trial.Newoption4 else trial.Newoption3]
/ timeout = 1
</trial>

<trial Newoption4>
/ ontrialbegin = [values.newoptionD = getitem(item.Newoptions,values.shuffleA1)]
/ ontrialbegin = [values.checkboxselect= getitem(item.selectedcount,values.shuffleA1)]
/ ontrialbegin = [if (values.checkboxselect== "1" ) values.newoption4=values.newoptionD]
/ ontrialend = [values.shuffleA1 = values.shuffleA1 + 1]
/ branch = [if (values.checkboxselect== "1" ) trial.Newoption5 else trial.Newoption4]
/ timeout = 1
</trial>


<trial Newoption5>
/ ontrialbegin = [values.newoptionE = getitem(item.Newoptions,values.shuffleA1)]
/ ontrialbegin = [values.checkboxselect = getitem(item.selectedcount,values.shuffleA1)]
/ ontrialbegin = [if (values.checkboxselect== "1" ) values.newoption5=values.newoptionE]
/ ontrialend = [values.shuffleA1 = values.shuffleA1 + 1]
/ branch = [if (values.checkboxselect== "1" ) trial.Newoption6 else trial.Newoption5]
/ timeout = 1
</trial>

<trial Newoption6>
/ ontrialbegin = [values.newoptionF = getitem(item.Newoptions,values.shuffleA1)]
/ ontrialbegin = [values.checkboxselect = getitem(item.selectedcount,values.shuffleA1)]
/ ontrialbegin = [if (values.checkboxselect== "1" ) values.newoption6=values.newoptionF]
/ ontrialend = [values.shuffleA1 = values.shuffleA1 + 1]
/ branch = [if (values.checkboxselect== "1" ) block.selectionchoosing else trial.Newoption6]
/ timeout = 1
</trial>
By Dave - 4/14/2016

The problem is that <item> elements do *not* resolve expressions, which is what

<item selectedcount>
/ 1 = "<%checkboxes.option1.selectedcount%>"
...
</item>

are. It's the *stimulus* element -- <text>, <picture>, etc. -- that uses the <item> element that's responsible for resolving expressions.

Hence, in your case values.checkboxselect will be equal to e.g. the *literal* string "<%checkboxes.option1.selectedcount%>", not "1" or "0".

Run the below example to see what I mean:

<values>
/ item_element = ""
/ text_element = ""
</values>

<checkboxes a>
/ options = ("a")
/ required = false
</checkboxes>

<surveypage a>
/ questions = [1=a]
</surveypage>

<text b>
/ items = b
</text>

<item b>
/ 1 = "<%checkboxes.a.selectedcount%>"
</item>

<trial b>
/ ontrialbegin = [values.item_element = getitem(item.b, 1);
    values.text_element = getitem(text.b, 1); ]

/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = ("Press CTRL+D and look at the two values")
</text>

<block myblock>
/ trials = [1 = sequence(a,b)]
</block>

The fix is to set up a <text> element referencing the item element as in the example above.
By Yuxi - 4/14/2016

Dear there,

Thank you so much! Your answer is very clear! Problem solved!

All the bests!