Have an idea?

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

Setting Predefined Values for a Rank Question Based on Another Rank Question

Hi all,

I have two questions where I ask respondents to rank a list of criteria. Both questions have the same list of criteria to be ranked. So I would like to get the answers of the first rank question and display them as predefined values in the second rank question.

However,

1) For both of the questions respondents are not obligated to rank all items, so in the first question we could have no answers for some of the criteria. In such a case, I want to have a blank field in the second question.

2) I would like to show the answers of the first question in the second one but also allow respondents to be able to change them on request.

Could you please help me?
Thank you
asked Aug 23, 2021 by Elif (140 points)
It sounds like these ranking questions are set to use numeric fields.  Is that correct?
It is correct, both questions have numeric fields.

1 Answer

+1 vote
Please try adding this script to your second ranking question:

<script>
$(document).ready(function(){
    [% Begin Unverified Perl
        # Params
        my $firstRanking = 'RankingQ1';
        my $items = 10;
        
        # Run
        my @ranks = ();
        for (my $i = 1; $i <= $items; $i++) {
            my $rank = GETVALUE($firstRanking . '_' . $i);
            push (@ranks, $rank);
        }
        return 'var ranks = [' . join(',', @ranks) . ']; var items = ' . $items . ';';
    End Unverified %]
    
    var answered = false;
    for (var i = 1; i <= items && !answered; i++) {
        answered = SSI_GetValue('[% QuestionName() %]_' + i);
    }
    if (!answered) {
        for (var i = 1; i <= items; i++) {
            $('#[% QuestionName() %]_' + i).val(ranks[i - 1]);
        }
    }
})
</script>


Line 5 should be updated with the name of the first ranking question.  Line 6 should be updated with the number of items that are involved in these questions.
answered Aug 23, 2021 by Zachary Platinum Sawtooth Software, Inc. (205,575 points)
It worked perfectly. Thanks a lot Zachary!
...