Have an idea?

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

Javascript Price Verification

Hello,
I'm trying to use javascript to verify some pricing, there are two questions that I'm asking, What price is a "Good Value" (q115) and what price is "Too Expensive" (q120).  These questions are on the same page and are in a loop with a constructed list.

Currently I'm using this code:
var a1 = SSI_GetValue("q115.[% LoopIteration() %]");
var a2 = SSI_GetValue("q120.[% LoopIteration() %]");
{

alert("Q115=" + SSI_GetValue("q115.[% LoopIteration() %]"));
alert("Q120=" + SSI_GetValue("q120.[% LoopIteration() %]"));

}

if(a1 == 0 && a2 == 0)
{
}
else if(a2 <= a1)
{
    strErrorMessage = "The TOO EXPENSIVE price must be higher than the GOOD VALUE price.";
}


I put in two alerts there to see if the values are coming up correctly.  It seems to bring in the correct question name (q120.1, etc.) but does not fill it with any values. Any help or ideas would be very much appreciated!!
asked Dec 20, 2018 by Geoff

1 Answer

+1 vote
Most of the time, the contents of a survey page (the HTML, CSS, and JS) don't actually know whether or not they're in a loop.  This is nice as it makes it so the scripts you need to use for looped questions are usually the same as the scripts you need to use for non-looped questions.  If you remove this from your verification, I think you'll be all set:

.[% LoopIteration() %]
answered Dec 20, 2018 by Zachary Platinum Sawtooth Software, Inc. (121,625 points)
Perfect, I should have tried that, I was assuming it needed the iteration number in there!  Thanks so much!
...