Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

CBC - Randomize Attribute Position - 2 subsets?

I want to randomize the attribute position, but there are 2 logical blocks (subsets) of attributes which has to be randomized.
Is there a possibility to do that? (I found only the possibility to randomize one subset of attributes...)
Or the possibility to randomize the attributes based on a construced list?

Additionally it would be greatful if I could query the shown order of attributes (at the moment i work with CBCATTRIBUTELABEL but I need the number instead of the label).

I use SSi version 7.0.26
asked Nov 17, 2016 by niemann

1 Answer

0 votes
Start by coding the necessary constructed list.  The parent list should be a list of all the CBC attributes.  The constructed list should include all the same elements as the parent list but randomized as necessary.  For example, if you want to randomize the first two attributes and the last two attributes, the constructed list needs to look like one of these: [1,2,3,4], [1,2,4,3], [2,1,3,4], or [2,1,4,3].

Now put this code in the CBC footer:

// Ordering
var order = [% ListValuesArray(RandAttList) %];
var order2 = [];
for (var i = 0; i < order.length; i++) {
    var origVal = order[i];
    var newVal = origVal;
    for (var j = 0; j < i; j++) {
        if (order[j] < origVal) {

// Remove spacers
var spacers = document.getElementsByClassName('spacer');
while (spacers.length > 0) {

// Reorder rows
var tbody = document.getElementsByClassName('cbc')[0].getElementsByTagName('tbody')[0];
var trs = tbody.getElementsByTagName('tr');
for (var i = 0; i < order2.length; i++) {
    var ithOrder = order2[i] - 1;
    var tr = trs[ithOrder].parentNode.removeChild(trs[ithOrder]);
var inputTr = trs[0].parentNode.removeChild(trs[0]);

// Fix none option
var noneOption = document.getElementsByClassName('none_option')[0];
var noneTd = noneOption.parentNode.removeChild(noneOption);

// Add spacers
var firstTr = trs[0];
var firstTrTds = firstTr.getElementsByTagName('td');
for (var i = firstTrTds.length - 1; i > 0; i--) {
    var node = document.createElement('td');
    node.className = 'spacer';
    node.setAttribute('rowspan', order.length + 1);
    node.innerHTML = '&nbsp;';
    firstTr.insertBefore(node, firstTrTds[i]);

"RandAttList" should be replaced with the name of the constructed list.  Lines 33-36 should be removed if you do not have a none option in the CBC.

When you want to know the order in which the attributes were randomized, you can simply read the values from the constructed list.

Please test this thoroughly to make sure it is working as you require.
answered Nov 17, 2016 by Zachary Platinum Sawtooth Software, Inc. (63,875 points)
Thanks for your answer, the code works very well.
So the randomization of two subsets is now possible and I am happy to have a list with the shown order because I need it in some other questions.
This is very helpful!
The code works fine in Chrome and Firefox but not in IE. I think its because of the meta tag <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"> - so in IE7 he don't know some javascript-functions. How could I remove the meta-tag (before loading the site)?
(SSi Version 7.0.26)
I'm not sure changing the meta tag is going to be enough.  Older versions of Internet Explorer, especially IE7 and below, are infamous for having lots of code that doesn't run right on them.  Are you certain that you need to support IE7?
No, I don't want to support IE7 or lower - but I have to support the actual IE 10, 11 etc.
but your code don't work also in acutal IE11! I think its because of the meta-Tag (ssi set them automaticly - I know in version 8 it was removed; but I have to use version 7 because of a cbc-project).
Is there a possibility to remove them?? (I have on many projects problems because a lot of possibilitys from javascript I cant use because of your meta-tag <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
Sorry.  I've looked into it, but there doesn't seem to be a built-in way to keep that particular meta tag from appearing in SSI Web v7.  You would need to make a modification to your study's .pl files in order to stop it from appearing.
Dear Zachary, thank you for your answer. I have modified my authlib-perl-script and now the reordering-code works very well in Internet Explorer too. I will test it carefully. I thank you very much for your help.