Have an idea?

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

Combo Box answer based upon previous column in grid

Hello,

I have Brand list as column1. I would like to show Brand model based upon selection at column1 on column2. How can this be possible?
asked Nov 28, 2013 by IL Bronze (1,580 points)

1 Answer

+3 votes
 
Best answer
I assume you have 3 option in column 1 and 2 model for each option in column 2. Code would be looks like.

<script type="text/javascript" src="/studyname/graphics/system/jquery-1.7.1.min.js"></script>

<script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function ($) {
  $('#Q1_r1_c1').on("change", function() {
        var i=1;
        for(i=1;i<=6;i++)
        {
            $("#Q1_r1_c2_"+i+"").remove(); 
        }
        var cattype = $(this).val(); 
    if (cattype == '1')
    { 
        $("#Q1_r1_c2").append('<option value="1" id="Q1_r1_c2_1">Option 1</option><option value="2" id="Q1_r1_c2_2">Option 2</option>');
                var i=1;
                for(i=3;i<6;i++)
                {
                    $("#Q1_r1_c2_"+i+"").remove(); 
        }
        }
    else if (cattype == '2')
    { 
        var i=1;
        for(i=1;i<=2;i++)
        {
            $("#Q1_r1_c2_"+i+"").remove(); 
        }
        $("#Q1_r1_c2").append('<option value="3" id="Q1_r1_c2_3">Option 3</option><option value="4" id="Q1_r1_c2_4">Option 4</option>');
        var i=1;
        for(i=5;i<=6;i++)
        {
            $("#Q1_r1_c2_"+i+"").remove(); 
        }
        }
        else if (cattype == '3')
        { 
            var i=1;
            for(i=1;i<=4;i++)
            {
                $("#Q1_r1_c2_"+i+"").remove(); 
            }
            $("#Q1_r1_c2").append('<option value="5" id="Q1_r1_c2_5">Option 5</option><option value="6" id="Q1_r1_c2_6">Option 6</option>');
            
        }
    else
    { 
        
        }
    });
    });
</script>


It will check the value at column 1 and will show only relative brand at column 2.
answered Dec 2, 2013 by Rajesh Rana Gold (23,625 points)
selected Dec 4, 2013 by IL
Dynamically change combo box answers
...