Have an idea?

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

Constant Sum & Exclusive

I have a constant sum question but I also need to incorporate a checkbox that says "this does not apply to me," which will overwrite the forced-answer of the constant sum.

A user cannot enter numbers in the input fields if the box is checked (or vice versa).

Is this possible? If so, how?
asked Apr 1, 2016 by WTW_cal Bronze (1,145 points)

1 Answer

0 votes
I accomplished this using a constant sum question and a select question on the same page.

For the constant sum, disable require response and use this custom JavaScript verification (found by clicking "Advanced..." in the question's settings):

var selectQuestion = 's';
var constantSumQuestion = 'cs';
var constantSumTotal = 100;

if (SSI_GetValue(selectQuestion + '_1') == 0 && $('#' + constantSumQuestion + '_total').val() != constantSumTotal)
{
    var strErrorMessage = 'Error.';
}


You will need to update the question names in lines 1 and 2, and also update the constant sum total in line 3.  Additionally, you can update the error message that will show up by changing line 7.

For the select question, use the list item "Does not apply" and set the question to use a check box.  Finally, put this code in the select question's footer:

<script type="text/javascript">
function SSI_CustomGraphicalCheckbox(GraphicalCheckboxObj, InputObj, BlnCheck)
{
    var selectQuestion = 's';
    var constantSumQuestion = 'cs';

    if (InputObj.name == selectQuestion + '_1')
    {
        var csInputSelector = '#' + constantSumQuestion + '_div .input_cell';
        var numOfCsItems = $(csInputSelector).length;
    
        if (BlnCheck)
        {
            for (var i = 1; i <= numOfCsItems; i++)
            {
                var field = '#' + constantSumQuestion + '_' + i;
                $(field).prop('disabled', true);
                $(field).val('');
            }
            $('#' + constantSumQuestion + '_total').val('');
        }
        else
        {
            for (var i = 1; i <= numOfCsItems; i++)
            {
                var field = '#' + constantSumQuestion + '_' + i;
                $(field).prop('disabled', false);
            }
        }
    }
}
</script>


Like before, you'll need to replace the constant sum and select questions' names in lines 4 and 5.
answered Apr 1, 2016 by Zachary Platinum Sawtooth Software, Inc. (67,650 points)
Fantastic! It works perfectly!
Overwriting error message
Need this to work with non-graphical checkbox
...