Have an idea?

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

Erorr message: "Your total must equal 100%"

I copied the steps in the linked page presented below, yet I won't progress to the next page (given the vars add to 100...).
It gives error message: "Your total must equal 100%"
Apparently, something in the Custom JavaScript Verification isn't working.
Any ideas?

asked Nov 6, 2020 by Tom
Can you post the code you have placed in your free format question?  Naturally, the "Q7" will have to be replaced with your question name and the "r1," ... "r5" will have to be replaced with the names of your free format variables.

Shot in the dark, but what are the variable settings applied to your free format variables?  If you add this line in the middle of the verification code, what shows up in the little pop up window when you go to submit the page with responses that should work?

var vartot=var1+var2+var3+var4+var5;
if (vartot != 100) {strErrorMessage = "Your total must equal 100%";}
Thanks for responding.

The alert seems to concatenate strings. E.g. I get "1010101010" after entering 10 as inputs five times.

How can I generate a numeric solution?

In the Variable Names-section I've defined Q7_rX as text (Numeric) and Q7_tot as Hidden. The question name is thus Q7 as in the example.

Thanks again.

1 Answer

0 votes
Looks like SSI_GetValue is coming up a little short for you.  It believes these input elements are meant to store text rather than a number, so it returns strings, which the custom JavaScript then concatenates rather than sums.  There are a few ways we could address this, but the simplest would be to just surround the SSI_GetValue calls with the Number function to convert them.

var var1 = Number(SSI_GetValue ("Q7_r1"));
answered Nov 6, 2020 by Zachary Platinum Sawtooth Software, Inc. (214,675 points)
Yep, that does the trick. Thanks!