Have an idea?

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

Response comparison/checking for two questions...

Hi! I am trying to create a question similar to this:

How much of TOPIC do you know? Answers must add up to 100%.
____ % subtopic
____ % subtopic
Don't Know Anything

What I did so far is create two questions, one for the constant sum and another for the select. Here are the conditions: If there are answers to the subtopics, then Dont Know must not be answered, same also the other way around.

Hope you can help me with this.
thanks!
asked Jul 11, 2012 by anonymous
retagged Sep 13, 2012 by Walter Williams

2 Answers

0 votes
Here we go.... assuming constant sum is "Q1" and second question is "Q1dk" and is a multiple response question (checkbox) with only one answer option ("Don't know anything")...

In Q1, you need to uncheck the "Require response to question" and in Q1dk you need to "Allow respondents to check any number of check boxes"

In the "Custom javascript verification" area for Q1.... paste in the following...

if(((document.mainform["Q1_1"].value==0)||(document.mainform["Q1_2"].value==0))&&(document.mainform["Q1dk_1"].checked==false))
{
  strErrorMessage = "Please enter an answer OR select Don't know anything";
}  

if(((document.mainform["Q1_1"].value>0)||(document.mainform["Q1_2"].value>0))&&(document.mainform["Q1dk_1"].checked==true))
{
  strErrorMessage = "You cannot enter an answer AND select Don't know anything";
}  

if(((parseInt(document.mainform["Q1_1"].value))+(parseInt(document.mainform["Q1_2"].value))!=100)&&(document.mainform["Q1dk_1"].checked==false))
{
  strErrorMessage = "Your answers do not sum to 100";
}  


There may be a more elegant way to do it... but it should do what you need it to.  Let me know if this doesn't work

Cheers
Russell
answered Jul 11, 2012 by rapizel Bronze (1,420 points)
Thank you so much! this has been very helpful!
0 votes
Similar to Russel's example before, just using the SSI_GetValue function (v7 or later).  Also assuming the first question is q1 and the second question is q1dk.

One difference is that with a constant sum question, you can actually check the totals box that we put up on the screen, so it's a little less code.

if(SSI_GetValue("q1_total") == 0 && SSI_GetValue("q1dk_1")==0)
{strErrorMessage = "Put in number or check the do not know box";}

if(SSI_GetValue("q1_total") > 0 && SSI_GetValue("q1dk_1")==1)
{strErrorMessage = "If you check the box, you remove the values from the subtopics";}
answered Jul 12, 2012 by Brian McEwan Gold Sawtooth Software, Inc. (38,990 points)
Do I really need to put the "SSI_GetValue"? I'm afriad the error message is not displaying and I cannot move on with this question upon testing.
SSI_GetValue is a function we've written that does some of the heavy lifting by figuring out what type something is, etc.  So, you can follow the other example here by calling a function by name and getting its value, while the SSI_GetValue is like a shortcut.

If you are having issues, I would recommend simplifying things.  Instead of a complex statement, try something like if(SSI_GetValue("q1_1") == 1).  Then check the first box and see if you can get an error to pop up.  Additionally, do a very simple error message to begin with to make sure your syntax is correct, i.e. {strErrorMessage="Error";}.
...