Have an idea?

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

JavaScript Error Message

I have two free form questions following a MaxDiff. The first free form question pulls in the best rated concept from the MaxDiff and the second free form question pulls in the worst rated concept from the MaxDiff. I have randomized the order in which respondents see these two free form questions. I am asking the respondent to rate the concepts from 1-100. However, I do not want the best question rated concept score to be lower than the worst rated concept score, and vice versa, but am having trouble coding this error message. My two free form questions are called Q2b1 and Q2b2 and the two variable names are Q2b1_bestlikelihood and Q2b2_worstlikelihood. My code is below and any input would be greatly appreciated. The "999" in the error message is a placeholder for me to pipe in the value from the best/worst rated concept. Thanks in advance!


if(SSI_GetValue("Q2b1_bestlikelihood")< "[%Q2b2_worstlikelihood%]")
strErrorMessage = "Based on your responses, it seems like you would be more interested in buying this package of diapers. Please enter a new answer that is greater than or equal to 999.";
asked Aug 25, 2017 by LisaVogl Bronze (530 points)

1 Answer

0 votes
Best answer
Adding the Sawtooth Script function "Shown" to your code seems like the best way to go.

Verification for Q2b1_bestlikelihood:

if ([% Shown(Q2b2) %] && SSI_GetValue('Q2b1_bestlikelihood') < Number('[% Q2b2_worstlikelihood%]')) {
    strErrorMessage = 'Error';

Verification for Q2b2_worstlikelihood:

if ([% Shown(Q2b1) %] && SSI_GetValue('Q2b2_worstlikelihood') > Number('[% Q2b1_bestlikelihood%]')) {
    strErrorMessage = 'Error';
answered Aug 25, 2017 by Zachary Platinum Sawtooth Software, Inc. (110,850 points)
selected Aug 27, 2017 by LisaVogl
Pipe in Value - Error Message