Have an idea?

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

Adding an Attribute column within ACA Pair question

Hi Team,

We have a requirement where we need to customized the pair question within ACA exercise and needs to insert an additional column at the start of the table where it should display the respective attributes names for the levels displayed.

In order to accomplish the above we need to get the values of the levels which are stored within left & right columns of the pair table and also the respective attribute value.

It would be great if you could provide us the functionality and the explanation as how random picking is done in this question as we could see we cannot use any kind of external list or any systems functions called within this question.

asked Mar 28, 2017 by AshishThakur (120 points)

1 Answer

+1 vote
I can't speak on how ACAs choose their pairs, but I can offer you this functionality using JavaScript.  I added this code to each of my ACA levels:

<input type="hidden" class="acaatt" value="ATTRIBUTE A"/>

Then I put this script in the footer of the ACA Pair questions:

.acacol {
    width: 10%;

.left_concept, .right_concept {
    width: 40%;

    $('#[% QuestionName() %]_div .acapair_table > tbody > tr').each(function(){
        var att = $(this).find('.acaatt').val();
        $(this).prepend('<td class="acacol">' + att + '</td>');
    $('#[% QuestionName() %]_div .inner_table > tbody > tr:last-child table > tbody > tr').prepend('<td class="acacol"></td>');
answered Mar 28, 2017 by Zachary Platinum Sawtooth Software, Inc. (182,000 points)
Hi Zachary,

I have reviewed and trying the above code.
Can please explain me the below line of code.
<input type="hidden" class="acaatt" value="ATTRIBUTE A"/>
in this you have taken value as ATTRIBUTE A.  This "ATTRIBUTE A" will come form question or you have taken randomly.
You can manually replace "ATTRIBUTE A" with whatever text you want.  That's the text that will be put into the attribute column when this level shows up in a Pair question.
Thanks Zachary.

Can you please let us know how to get the value from this below code using perl script

<input type="hidden" name="acaatt" value="-99,-55,-66,-22,101,56,65,20"/>

the above code we want 55. so we have used below JQuery code but based on our requirement we want this code in to perl.
<script type="text/javascript">
var kx=$("input[name='hid_E1_Pair1']").val();
var kxs=kx.split(',');

var kx1=Math.abs(kxs[1]);
I'm sure I could handle string splitting and absolute values in Perl, but this line cannot be directly converted to Perl:

var kx = $("input[name='hid_E1_Pair1']").val();

That line is reading a value from the page, which works because JavaScript is ran on the page.  Perl, on the other hand, is ran on the server, so it cannot read a value from the page; the Perl needs to be given that string some other way.  Is the string constant?  If so, I could just hard code it into the new Perl instead of reading it from a page input.
Thanks for the explanation Zachary.

we can the above line as bow 2 types:
1) var kx = $("input[name="+"hid_E1_Pair1"+"]").val();
using string concatenation
2)  var kx = $("input[name=\"hid_E1_Pair1\"]").val();
using \ escaping character

we have converter above line into perl , but we are not able to split and store the value.

our conversion code is below

using escaping character
Is your goal to create Perl that does all the calculations (so the Perl returns "55"), or do you just want Perl that generates that JavaScript (so the Perl returns "<script>...</script>")?
My goal is Perl returns "55".
In that case, this line of code is the wrong direction:


You see, Perl is 100% done before any JavaScript is ran.  So if you were to print out the value of $msg, you would get "kx=$(...).val();", not "-99,-55,-66,...".  It's like a one-way phone call: you can send information from Perl to JavaScript, but not the other way around.  So Perl needs to get "-99,-55,-66,..." some way that doesn't involve JavaScript.

The question I need answered is where does "-99,-55,-66,..." come from?  Is it a constant?  Is it a pass-in field?  Is it the output of some SSI Script code?