Have an idea?

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

Dropdown Ranking

We are using a dropdown ranking question with 10 items to rank. As it is rather difficult for the respondents to keep in mind which ranks they have already used, the following would be helpful: When the respondent gives a rank to item 1, the other dropdowns would automatically been updated and this rank is removed from the answer options.

Would this be possible? Any ideas would be appreciated!
asked Mar 19 by ingo (340 points)

1 Answer

0 votes
 
Best answer
Please try adding this to your ranking question:

<script>
$(document).on('ready', function(){
    $('#[% QuestionName() %]_div select').change();
})

$(document).on('change', '#[% QuestionName() %]_div select', function(){
    // Parameters
    var numberOfOptions = 10;
    
    // Run
    var list = $('input[name="hid_list_[% QuestionName() %]"]').val().split(',');
    
    var usedOptions = {};
    list.forEach(function(item){
        usedOptions[SSI_GetValue('[% QuestionName() %]_' + item)] = true;
    });
    
    list.forEach(function(item){
        var resp = SSI_GetValue('[% QuestionName() %]_' + item);
        var select = $('#[% QuestionName() %]_' + item);
        $(select).find('option[id^="[% QuestionName() %]_"]').remove();
        for (var i = 1; i <= numberOfOptions; i++) {
            if (!usedOptions[i] || resp == i) {
                $(select).append('<option value="' + i + '" id="[% QuestionName() %]_' + item + '_' + i + '">' + i + '</option>');
            }
        }
        if (resp) {
            $(select).val(resp);
        }
    });
});
</script>
answered Mar 19 by Zachary Platinum Sawtooth Software, Inc. (127,375 points)
selected Mar 20 by ingo
Hi Zachary,

Great work as always! Thank you very much, it works perfectly!
...