Have an idea?

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

Display a warning (not error) message based on a comparison of 2 answers

I would like to display a warning message based on a comparison of 2 answer values (not an error that stop people proceeding).

Hope someone can help, more details follow,
thanks
Dan

I have a Grid question (with some javascript to make it appear like a thermometer with a slider for people to record their health score out of 100) = (“hs_r1_c1”)

Later they enter another health score (“newhs_r1_c1”).

I would like a message to appear if their new health score is less than, or equal to, their original score - to check they meant this to happen.

These should not be errors that stop people proceeding  - just flagging it to avoid inadvertent bad answers.

This would need to go on the page which features the second Grid question ("newhs_r1_c1").

Something like:
if (SSI_GetValue ("hs_r1_c1") == SSI_GetValue ("newhs_r1_c1")  )
{
strErrorMessage = “we noticed your new health score is the same as you scored it today – is that right? If not, please adjust your new score”;
}
if (SSI_GetValue ("hs_r1_c1") > SSI_GetValue ("newhs_r1_c1")  )
{
strErrorMessage =“we noticed your new health score is lower (worse) than you scored it today – is that right? If not, please adjust your new score”;
}
asked Aug 12, 2021 by dan r Bronze (4,025 points)
The solution depends on how you want this warning to work.  One way I've seen users do this is to code their custom JavaScript to only show the error message the first time the next button is clicked.  Another option would be to use JavaScript events to display a message on the page dynamically whenever their responses meet this criteria.  Are either of those close to what you're after?
Thanks Zachary
I think the first option would work well for us.
First click of NEXT generates the message, a second click of Next would allow them to proceed despite the odd response,

Dan

1 Answer

0 votes
Sounds good.  Add this HTML to some question text field on the page:

<input type="hidden" id="warningFlag"/>


Then you just need to wrap your custom JavaScript verification like this:

var hiddenInput = $('#warningFlag');
if (!hiddenInput.val()) {
    hiddenInput.val(1);
    ...
}


Line 4 is where you should put your regular verification rules.
answered Aug 12, 2021 by Zachary Platinum Sawtooth Software, Inc. (206,100 points)
Many thanks Zachary, I gave that a try but it is not working  for me.
I put
  <input type="hidden" id="warningFlag"/>  

into the header of the second Question (noFHhealthscore).
In the "Custom JavaScript Verification" tab of the second Question (noFHhealthscore) I put this code:
var hiddenInput = $('#warningFlag');
if (!hiddenInput.val()) {
    hiddenInput.val(1);
    if (SSI_GetValue("healthscore_r1_c1") == SSI_GetValue("noFHhealthscore_r1_c1"))
{
strErrorMessage = "we noticed your new health score is the same as you scored it today – is that right? If not, please adjust your new score";
}
else if (SSI_GetValue("healthscore_r1_c1") > SSI_GetValue("noFHhealthscore_r1_c1"))
{
strErrorMessage = "we noticed the health score you entered without your food hypersensitivity is lower (worse) than you scored it today – is that right? If not, please adjust your new score";
}
}

I set this to run after the built in question JavaScript verification (I tried it after also)
There is no Error message but the NEXT button  just operates normally even if one of the conditions that should trigger the message is met.

thanks

Dan
I tried answering healthscore_r1_c1 with a value higher than my response to noFHhealthscore_r1_c1 and saw the error message.  Perhaps the issue lies with your sliders - can you share an .ssi demonstrating the problem with our support team?
Thanks Zachary
That's  interesting - I had the same thought re my sliders  so earlier today I set up the error message in the second of  2 simple numeric Qs - and I could not get the message to display!

I'll send in the .ssi file
Thanks for your help on this

Dan
Now I understand ..... my questions are on different pages - the code works when the Qs are on the same page.
So I needed [%healthscore_r1_c1%]  for the value entered on the previous page
 
if ([%healthscore_r1_c1%] == SSI_GetValue("noFHhealthscore_r1_c1"))
{
strErrorMessage = "we noticed your new health score without your food hypersensitivity is the same as you scored it today – is that right? If not, please adjust your new score";
}
else if ([%healthscore_r1_c1%] > SSI_GetValue("noFHhealthscore_r1_c1"))
{
strErrorMessage = "we noticed the health score you entered without your food hypersensitivity is lower (worse) than you scored it today – is that right? If not, please adjust your new score";
}
...