Have an idea?

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

how could i use javascript to create constructed list based on response of another drop down question on same page

asked Apr 23 by anonymous
Constructed lists cannot be defined with JavaScript, but it is possible to effectively achieve this by hiding / disabling certain parts of a question based on the response to another question on the same page.  Can you tell us more about the second question on your page and the behavior you want to occur?
Yes i have my first question on a screen as a normal drop down select question. My second question is on same page but is hidden till the time we have some response in our first question. Second question is single select type question whose options i want are to be based on option selected in question 1 so is there any way out to do so...

1 Answer

+1 vote
Try placing this script in your second select question:

#[% QuestionName() %]_div {
    display: none;


$(document).on('change', 'select', updateDependentQuestion);

function updateDependentQuestion() {
    var independentQuestion = 'Q1';
    var response = SSI_GetValue(independentQuestion);
    if (!response) {
        $('#[% QuestionName() %]_div').hide();
    else {
        $('#[% QuestionName() %]_div .clickable').hide();
        switch (response) {
            case 1:
                $('#[% QuestionName() %]_1').closest('.clickable').show();
                $('#[% QuestionName() %]_2').closest('.clickable').show();
                $('#[% QuestionName() %]_3').closest('.clickable').show();
            case 2:
                $('#[% QuestionName() %]_4').closest('.clickable').show();
            case 3:
                $('#[% QuestionName() %]_5').closest('.clickable').show();
                $('#[% QuestionName() %]_6').closest('.clickable').show();
        if (!$('#[% QuestionName() %]_' + SSI_GetValue('[% QuestionName() %]') + '_graphical').is(':visible')) {
            SSI_RadioReset('[% QuestionName() %]');
        $('#[% QuestionName() %]_div').show();

Line 15 must be updated with the name of the first select question.  Lines 25 - 36 must be updated with the nature of which items are to be shown for which responses to the first select question.
answered Apr 23 by Zachary Platinum Sawtooth Software, Inc. (121,425 points)