Have an idea?

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

Filling a Grid Column with Predefined Values depending on a Previous Answer

Hi,

I have a grid consisting of competitor names as columns and criteria as rows. I would like to prefill each column depending on the respondents answers on which competitors they are working with. So, I have a select question, Q1 and if the first competitor is chosen that is Q1_1=1, I would like to fill the each input box in the first column of the grid with value 0. If otherwise is true, and Q1_1=0, I would like to fill the column with 8's. That is QGrid_r1_c1=8, QGrid_r2_c1=8...

Could you help me with a code on how to do this?
Thanks a lot!
asked Apr 14 by Elif

1 Answer

0 votes
Please try adding this script to your grid question:

<script>
$(document).ready(function(){
    // Params
    var selectResp = Number([% SelectQ_1 %]);
    
    // Run
    var defaultValue = selectResp ? 0 : 8;
    $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',').forEach(function(row){
        var input = $('#[% QuestionName() %]_r' + row + '_c1');
        if (!$(input).val()) {
            $(input).val(defaultValue);
        }
    });
})
</script>


"SelectQ" must be replaced with the name of your select question.
answered Apr 14 by Zachary Platinum Sawtooth Software, Inc. (171,950 points)
It worked perfectly, thanks a lot!
...