Millisecond Forums

Problem with checkboxes

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

By nkleinselle - 4/9/2022

Hi everyone,

At the beginning of my experiment, participants need to pick "significant items" from a list by checking the checkboxes next to it (there are 4 such lists: significantLastname, significantMothername, significantBirthcity, significantFavoritecity).

In the output (data), I correctly see which items were marked. However, the marked items should also be removed from another (identical) list and not appear in the rest of the experiment. However, they do appear in the experiment... Please see below part of the script. Im also attaching the entire exp as a zip. file.

I hope someone can help :)
Nathalie




<checkboxes significantLastname>
/ required = false
/ range = (0,12)
/ position = (80%, 35%)
/ size = (80%, 50%)
/ options = (    "אלדן",
                "אלרון",
                "גרינברג",
                "גולדברג",
                "שטרית",
                "שילון",
                "אגמון",
                "מרידור",
                "רחמים",
                "כוכבי",
                "תירוש",
                "אבנרי",
                "בנימיני",
                "רשף",
                "אוחנה",
                "לוינסון"
                )
</checkboxes>

<surveypage significantLastname>
/ questions = [1 = significantLastnameInstructions, significantLastname]
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
/ itemfontstyle = ("Arial", 3%, true, false, false, false, 5, 1)
/ responsefontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txcolor = (0, 0, 0)
/ showpagenumbers = false
/ showquestionnumbers = false
/ ontrialend = [
        if(checkboxes.significantLastname.checked.1) {
   item.Lastnames.removeitem(1);
  };
   if(checkboxes.significantLastname.checked.2) {
   item.Lastnames.removeitem(2);
  };
   if(checkboxes.significantLastname.checked.3) {
   item.Lastnames.removeitem(3);
  };
   if(checkboxes.significantLastname.checked.4) {
   item.Lastnames.removeitem(4);
  };
        if(checkboxes.significantLastname.checked.5) {
   item.Lastnames.removeitem(5);
  };
        if(checkboxes.significantLastname.checked.6) {
   item.Lastnames.removeitem(6);
  };
        if(checkboxes.significantLastname.checked.7) {
   item.Lastnames.removeitem(7);
  };
        if(checkboxes.significantLastname.checked.8) {
   item.Lastnames.removeitem(8);
  };
        if(checkboxes.significantLastname.checked.9) {
   item.Lastnames.removeitem(9);
  };
        if(checkboxes.significantLastname.checked.10) {
   item.Lastnames.removeitem(10);
  };
        if(checkboxes.significantLastname.checked.11) {
   item.Lastnames.removeitem(11);
  };
        if(checkboxes.significantLastname.checked.12) {
   item.Lastnames.removeitem(12);
  };
        if(checkboxes.significantLastname.checked.13) {
   item.Lastnames.removeitem(13);
  };
        if(checkboxes.significantLastname.checked.14) {
   item.Lastnames.removeitem(14);
  };
        if(checkboxes.significantLastname.checked.15) {
   item.Lastnames.removeitem(15);
  };
        if(checkboxes.significantLastname.checked.16) {
   item.Lastnames.removeitem(16);
  };
]
/ ontrialend = [
  var i = 0;
  while (i < item.Lastnames.itemcount){
   i += 1;
   list.controlLastname.appenditem(i);
  };
  item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
  item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
  item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
  item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
  ]
</surveypage>

<list controlLastname>
/ selectionrate = always
</list>
By nkleinselle - 4/9/2022

Some clarification...
In this part of the script, it should randomly pick 4 items from the list (after removing all significant items). I think the mistake is there maybe...

/ ontrialend = [
var i = 0;
while (i < item.Lastnames.itemcount){
 i += 1;
 list.controlLastname.appenditem(i);
};
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
]
</surveypage>

<list controlLastname>
/ selectionrate = always
</list>
By Dave - 4/11/2022

nkleinselle - 4/9/2022
Some clarification...
In this part of the script, it should randomly pick 4 items from the list (after removing all significant items). I think the mistake is there maybe...

/ ontrialend = [
var i = 0;
while (i < item.Lastnames.itemcount){
 i += 1;
 list.controlLastname.appenditem(i);
};
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
item.controlItems.appenditem(item.Lastnames.item(list.controlLastname.nextvalue));
]
</surveypage>

<list controlLastname>
/ selectionrate = always
</list>

Your logic for removing items is flawed. When you remove item 1 from the item element, what was previously item 2 is item number 1 after the removal of the first item.

So, this whole section here

/ ontrialend = [
   if(checkboxes.significantLastname.checked.1) {
 item.Lastnames.removeitem(1);
};
 if(checkboxes.significantLastname.checked.2) {
 item.Lastnames.removeitem(2);
};
 if(checkboxes.significantLastname.checked.3) {
 item.Lastnames.removeitem(3);
};
 if(checkboxes.significantLastname.checked.4) {
 item.Lastnames.removeitem(4);
};
   if(checkboxes.significantLastname.checked.5) {
 item.Lastnames.removeitem(5);
};
   if(checkboxes.significantLastname.checked.6) {
 item.Lastnames.removeitem(6);
};
   if(checkboxes.significantLastname.checked.7) {
 item.Lastnames.removeitem(7);
};
   if(checkboxes.significantLastname.checked.8) {
 item.Lastnames.removeitem(8);
};
   if(checkboxes.significantLastname.checked.9) {
 item.Lastnames.removeitem(9);
};
   if(checkboxes.significantLastname.checked.10) {
 item.Lastnames.removeitem(10);
};
   if(checkboxes.significantLastname.checked.11) {
 item.Lastnames.removeitem(11);
};
   if(checkboxes.significantLastname.checked.12) {
 item.Lastnames.removeitem(12);
};
   if(checkboxes.significantLastname.checked.13) {
 item.Lastnames.removeitem(13);
};
   if(checkboxes.significantLastname.checked.14) {
 item.Lastnames.removeitem(14);
};
   if(checkboxes.significantLastname.checked.15) {
 item.Lastnames.removeitem(15);
};
   if(checkboxes.significantLastname.checked.16) {
 item.Lastnames.removeitem(16);
};
]

will in effect remove the wrong items.

Consider this simple example, removing items 1 and 2 -- in this order -- from the item element.

<block myblock>
/ onblockbegin = [
    item.myitem.removeitem(1);
    item.myitem.removeitem(2);
]

/ postinstructions = (end)
</block>

<item myitem>
/ 1 = "a"
/ 2 = "b"
/ 3 = "c"
/ 4 = "d"
</item>

<page end>
Items left in item element:
<%item.myitem.item(1)%>
<%item.myitem.item(2)%>
</page>


You might think this would result in the removal of item "a" and "b", but that's wrong. It will remove item "a". Item "b" then immediately is the new item 1, and the new item 2, "c" will be removed.

The simple fix to this is to work backwards:

<block myblock>
/ onblockbegin = [
    item.myitem.removeitem(2);
    item.myitem.removeitem(1);
]
/ postinstructions = (end)
</block>

<item myitem>
/ 1 = "a"
/ 2 = "b"
/ 3 = "c"
/ 4 = "d"
</item>

<page end>
Items left in item element:
<%item.myitem.item(1)%>
<%item.myitem.item(2)%>
</page>

By nkleinselle - 4/12/2022

Thank you very much!! :)