Have an idea?

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

Creating a Custom Javascript Error when Respondent selects the same response

I have 2 questions on the same page, both "SELECT" type questions called Q1 and Q2. For more background info...Questions Q1 & Q2 pertain to a statement that I will list above them in a header that talks about a new product statement.  

Q1 asks which sentence is your favorite and lists select choices 1 through 6 (single response). Then Q2 asks, which sentence is your least favorite and then again lists selection choices 1 through 6 (single response)

My question is how do I NOT allow the respondent to select the same response in Q2 as was chosen in Q1? I've tried creating some custom java and it pops up with an error, but then moves on to the next page. I want the respondent to correct their mistake before it allows them to move on. Here is what I created... I'm using SSI Web version 7. Please help.

var FLY1 = SSI_GetValue("Q1");  
 
var FLY2 = SSI_GetValue("Q2");  
    
 if(FLY1 = FLY2)  
 
 {  
   
 alert("You cannot select the same statement.");  
 
   }  
 
//You cannot select the same statement.
asked Jan 3 by anonymous

2 Answers

0 votes
Version 7 is no longer supported, but you should be able to find an example of adding custom JavaScript verification in the Help documentation.  Search for the word JavaScript and you should be able to find a page that I think is titled something like "JavaScript in SSI Web" that has a few sections.  One of those sections should be how to add custom validation to a page.

I'm also not 100% sure SSI_GetValue()  existing in version 7, so double check in that same area under the JavaScript functions to make sure it's there.
answered Jan 3 by Brian McEwan Gold Sawtooth Software, Inc. (37,385 points)
0 votes
To check if two values are equal in JavaScript, you need to use "==" instead of "=".

You can keep your alert if you want, but you'll also need to set the error message so that the page does not submit.

if (FLY1 == FLY2)
{
    alert("You cannot select the same statement.");
    strErrorMessage = "You cannot select the same statement.";
}
answered Jan 4 by Zachary Platinum Sawtooth Software, Inc. (67,300 points)
Thanks Zach...

Here is what I have and it is still advancing... Any ideas? Thanks!

var FLY1 = SSI_GetValue("Q1");  
 
var FLY2 = SSI_GetValue("Q2");  
    
  
if (FLY1 == FLY2)
{
    alert("You cannot select the same statement.");
    strErrorMessage = "You cannot select the same statement.";
}

//You cannot select the same statement.
Did you verify that SSI_GetValue exists in v7?
...