Have an idea?

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

Constant Sum - Not allowing the value of zero

Hello,

I have a constant sum question where it is based on answers chosen in a previous question.

I would like not  to allow the value of zero for any answer in my constant sum question.  

I am generating the list of answer choices for the constant sum question  by constructing a list of all answers chosen in the pervious question.

I believe this will involve JavaScript.  Has anyone done this before?

Thank you in advance.
asked Aug 11, 2017 by Sandy

1 Answer

+1 vote
Try this custom JavaScript verification:

var items = $('input[name="hid_list_[% QuestionName() %]"]').val().split(',');
items.forEach(function(item){
    if (SSI_GetValue('[% QuestionName() %]_' + item) == 0) {
        strErrorMessage = 'Error.';
    }
})
answered Aug 11, 2017 by Zachary Platinum Sawtooth Software, Inc. (89,650 points)
Hi Zachary - Thank you for your assistance.  I am getting an error:  The function call Q19a does not exist.  Q19a is a grid where the answer choices are being displayed based on the answers chosen at a previous question.
The Sawtooth Script "[% QuestionName() %]" is automatically replaced with the name of the question that calls the script.  You should not replace "QuestionName" with the name of your question.

Is this actually a constant sum question or is it a constant sum-type grid question?  If it is a grid, my code will need to be updated to reflect that.
Hi Zachary - I am not getting an error but I am also not getting an message pop up to come up when I enter 0 in for one of the answers.
Are you using a grid question?
Yes, it is a grid question so I added  _r  +  item  +  "_c1" and was getting ready to test
ok.. sorry to be a bother but what I tried did work either the question is a constant-sum-type grid question with 1 column and the rows are based on the previous question.
Adding the "_r" and "_c" is a good start.  The code is failing because line 1 does not work for grid questions.  Try replacing line 1 with this:

var items = $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',');
Where do I send you the champagne?  It worked!  Thank you sooo much have a wonderful weekend.. this was greatly appreciated
Ha ha, I'm glad we got it squared away.  Have a great weekend as well.
...