Have an idea?

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

Constant sum scale with "None of the above" attribute

I have constant sum scale question with "none of the above" attribute. To avoid entering responses in other attributes and "none of the above", i have used the below JS. Can any one help me to fix the error in this code?

Also, is there any alternate approach for handling "None of the above attribute" in Constand sum scale?

 
var strErrorMessage = "";

var q7_1Val = SSI_GetValue("Q7_1");
var q7_2Val = SSI_GetValue("Q7_2");
var q7_3Val = SSI_GetValue("Q7_3");
var q7_4Val = SSI_GetValue("Q7_4");
var q7_5Val = SSI_GetValue("Q7_5");
var q7_6Val = SSI_GetValue("Q7_6");
var q7_7Val = SSI_GetValue("Q7_7");
var q7_8Val = SSI_GetValue("Q7_8");
var q7_9Val = SSI_GetValue("Q7_9");
var q7_10Val = SSI_GetValue("Q7_10");
var q7_11Val = SSI_GetValue("Q7_11"); 

var q7_sum = q7_1Val+q7_2Val+q7_3Val+q7_4Val+q7_5Val+q7_6Val+q7_7Val+q7_8Val+q7_9Val+q7_10Val;

if ((document.mainform["Q7_11"].value).length >= 0 && q7_sum>=0)
{
 var strErrorMessage = "None of these can only be 0 or 100.";
}

asked Oct 26, 2012 by Lawrence Bronze (2,100 points)
edited Oct 26, 2012 by Walter Williams

1 Answer

0 votes
 
Best answer
Hi Lawrence,
using an alert just after
var q7_sum = q7_1Val+q7_2Val+q7_3Val+q7_4Val+q7_5Val+q7_6Val+q7_7Val+q7_8Val+q7_9Val+...

line should hint on the cause of the problem
alert (q7_sum);

you will probably get something like "102000050", I guess the variables are initialized as string. So either change your declarations to var q7_1Val = 0 and then assign with SSI_GetValue or use parseInt(SSI_GetValue()) to make sure they are handled as numbers.

Another thing might be if you are using a constructed list for the constant sum, if that is the case you need to check existence of each Q7_x so that it doesnt cause JS errors
answered Oct 26, 2012 by Bahadir Ozkurt Gold (17,010 points)
selected Oct 26, 2012 by Lawrence
Bahadir,

Thanks for your help. The alert command helped me to understand what values is getting stored.

I have modified little bit the IF statement condtions and it works now.

Here is the final code for other users reference.

var strErrorMessage = "";

var q7_1Val = SSI_GetValue("Q7_1");
var q7_2Val = SSI_GetValue("Q7_2");
var q7_3Val = SSI_GetValue("Q7_3");
var q7_4Val = SSI_GetValue("Q7_4");
var q7_5Val = SSI_GetValue("Q7_5");
var q7_6Val = SSI_GetValue("Q7_6");
var q7_7Val = SSI_GetValue("Q7_7");
var q7_8Val = SSI_GetValue("Q7_8");
var q7_9Val = SSI_GetValue("Q7_9");
var q7_10Val = SSI_GetValue("Q7_10");
var q7_11Val = SSI_GetValue("Q7_11"); 

var q7_sum = q7_1Val+q7_2Val+q7_3Val+q7_4Val+q7_5Val+q7_6Val+q7_7Val+q7_8Val+q7_9Val+q7_10Val;

if (q7_11Val > 0 && q7_sum > 0)
{
 var strErrorMessage = "None of these can only be 0 or 100.";
}
cheers :)
Hi, I´m trying to apply this code in my Project. Do you know which part of the JS should I insert this? Thanks
...