Have an idea?

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

Java Script problem on ranges

Hello,

I have two questions.

The first question(S23A) is  grid question with the below ranges in columns

1. 1
2. 2-9
3. 10+

The second question (S23B) is follow up question from first, if any one answered 2-9 OR 10+ we ask exact numer in numeric box.

I have used the below code for evaluating numeric response with the ranges specified in first question. I am not sure what is the mistake here. It not at all showing error message.

Can any one tell me what is the problem?

var strErrorMessage1 = ""; 
var strErrorMessage2 = ""; 

var B1=SSI_GetValue("S23B_r1_c1");
var B2=SSI_GetValue("S23B_r2_c1");
var B3=SSI_GetValue("S23B_r3_c1");
var B4=SSI_GetValue("S23B_r4_c1");
var B5=SSI_GetValue("S23B_r5_c1");
var B6=SSI_GetValue("S23B_r6_c1");

if ((SSI_GetValue ("S23A_r1") == 2) && (B1<2 || B1>9)) { var strErrorMessage1 = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r2") == 2) && (B2<2 || B2>9)) { var strErrorMessage1 = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r3") == 2) && (B3<2 || B3>9)) { var strErrorMessage1 = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r4") == 2) && (B4<2 || B4>9)) { var strErrorMessage1 = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r5") == 2) && (B5<2 || B5>9)) { var strErrorMessage1 = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r6") == 2) && (B6<2 || B6>9)) { var strErrorMessage1 = "Please enter number between 2 and 9";}

if ((SSI_GetValue ("S23A_r1") == 3) && (B1<10 || B1>100)) { var strErrorMessage2 = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r2") == 3) && (B2<10 || B2>100)) { var strErrorMessage2 = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r3") == 3) && (B3<10 || B3>100)) { var strErrorMessage2 = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r4") == 3) && (B4<10 || B4>100)) { var strErrorMessage2 = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r5") == 3) && (B5<10 || B5>100)) { var strErrorMessage2 = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r6") == 3) && (B6<10 || B6>100)) { var strErrorMessage2 = "Please enter number between 10 and 100";}

asked Sep 21, 2012 by Lawrence Bronze (2,100 points)
retagged Sep 21, 2012 by Walter Williams

1 Answer

0 votes
change it to
var B1=SSI_GetValue("S23B_r1_c1");
var B2=SSI_GetValue("S23B_r2_c1");
var B3=SSI_GetValue("S23B_r3_c1");
var B4=SSI_GetValue("S23B_r4_c1");
var B5=SSI_GetValue("S23B_r5_c1");
var B6=SSI_GetValue("S23B_r6_c1");
 
if ((SSI_GetValue ("S23A_r1") == 2) && (B1<2 || B1>9)) { strErrorMessage = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r2") == 2) && (B2<2 || B2>9)) { strErrorMessage = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r3") == 2) && (B3<2 || B3>9)) { strErrorMessage = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r4") == 2) && (B4<2 || B4>9)) { strErrorMessage = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r5") == 2) && (B5<2 || B5>9)) { strErrorMessage = "Please enter number between 2 and 9";}
if ((SSI_GetValue ("S23A_r6") == 2) && (B6<2 || B6>9)) { strErrorMessage = "Please enter number between 2 and 9";}
 
if ((SSI_GetValue ("S23A_r1") == 3) && (B1<10 || B1>100)) { strErrorMessage = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r2") == 3) && (B2<10 || B2>100)) { strErrorMessage = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r3") == 3) && (B3<10 || B3>100)) { strErrorMessage = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r4") == 3) && (B4<10 || B4>100)) { strErrorMessage = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r5") == 3) && (B5<10 || B5>100)) { strErrorMessage = "Please enter number between 10 and 100";}
if ((SSI_GetValue ("S23A_r6") == 3) && (B6<10 || B6>100)) { strErrorMessage = "Please enter number between 10 and 100";}
answered Sep 21, 2012 by Bahadir Ozkurt Gold (17,010 points)
This code is not showing error. Simply it goes to next screen. I did Custom Java script verification before and after the system Java script error. But no use.

I have numeric question settings as Min=1, Max=100. Otherwise everything looks good to me.

Also, what will happen if we need to display error message for 2-9 and 10+ ranges simultaneously?
second part needs to be strErrorMessage = strErrorMessage + "Please enter number between 10 and 100";
to show two errors next to each other.
What Bahadir is referencing is that we create a variable called strErrorMessage and it starts out blank.  If it stays blank, the page submits.  If it is assigned a value, the page refreshes and we print the value on the screen as an error message.  In your code, you have made your own variables called strErrorMessage1 and strErrorMessage2.  Assigning these a value will not trigger our custom validation behavior and the page will submit.
...