Have an idea?

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

Scripting Question for Volumetric (Allocation) CBC - possible to implement drop down for allocation text box?

I have a question regarding formatting the input box for Constant Sum/Allocation CBC. Currently, if you select Constant Sum/Allocation in the Format tab, it gives the respondent an input box. The range of answers respondents can enter are customizable in the Settings to include a range & total. Is there a script to convert/format the input text box to become a drop down with a set range of items (with default being 0)?

I imagine changing this input box to a drop down affect data and results given the limits/ restrictions the drop down would have. Is the ample concern here to caution against using a drop down?

Thanks!
asked Aug 8 by Marco Z (140 points)

1 Answer

0 votes
Put this code in your CBC's footer:

<style>
.cbc .numeric_input {
    display: none;
}
</style>

<script>
$(document).ready(function(){
    var options = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50];
    
    var dropdownHtml = '<select class="cbcDropdown">';
    options.forEach(function(option){
        dropdownHtml += '<option value="' + option + '">' + option + '</option>';
    });
    dropdownHtml += '</select>';
    $('.cbc .numeric_input').each(function(){
        $(this).after(dropdownHtml);
        $(this).siblings('.cbcDropdown').val($(this).val());
    });
    $('.cbcDropdown').change(function(){
        $(this).siblings('.numeric_input').val($(this).val());
        $(this).siblings('.numeric_input').keyup();
    });
})
</script>


Line 9 should be updated with the options you want in the dropdowns.
answered Aug 8 by Zachary Platinum Sawtooth Software, Inc. (63,900 points)
...