Have an idea?

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

Autofill Grid Ranking Question

I have a grid question, with 5 rows and one column.  Each row contains a statement and in the first column, the respondent will rank each statement using a combo box.  They can choose from "Most appealing," "Second," "Third," "Fourth," and "Least Appealing."  

I was asked to make the question so that when a respondent ranks four out of the five statements, the fifth statement will be automatically filled in for them.  How can I do this?

Thanks in advance!
asked Jan 29 by anonymous

1 Answer

+1 vote
 
Best answer
Try adding this script to your grid question:

<script>
$(document).ready(function(){
    $('#[% QuestionName() %]_div select').change(function(){
        if ($(this).val()) {
            var resps = [1, 2, 3, 4, 5];
            var emptySelect;
            
            $('#[% QuestionName() %]_div select').each(function(){
                var value = $(this).val();
                if (value) {
                    for (var i = 0; i < resps.length; i++) {
                        if (resps[i] == value) {
                            resps.splice(i, 1);
                            break;
                        }
                    }
                }
                else {
                    emptySelect = $(this);
                }
            });
            
            if (resps.length == 1) {
                $(emptySelect).val(resps[0]);
            }
        }
    });
})
</script>
answered Jan 30 by Zachary Platinum Sawtooth Software, Inc. (127,900 points)
Thanks Zachary!  It works perfectly.
...