# Access answer in Assessment Result Message

6 years 1 week ago #56759 by thaJack
I would like to have my assessment result message display two different things based on the answer to a specific question.

For example, if the assessment score is 100, it will display the appropriate message. That works perfectly right now.

But, I want the message to have something dynamic in it. For example:

If (answer to question 11111X2X3 = "YES")
Then display "this text"
ElseIf (answer to question 11111X2X3 = "NO")
Then display "that text"

How would I go about doing that?

6 years 1 week ago #56760 by tpartner
You should be able to create 2 assessments for the same question(s) with different ranges to display different messages.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

6 years 1 week ago - 6 years 1 week ago #56761 by thaJack
Yes, but that won't work for me. Let's say I were making a test and a score of 100+ were passing.

In the end, the assessment score is 150. It will display the appropriate assessment message for that score.

However, if the answer to question 11111X2X3 is "YES", I also want it to display something else with it.

Having multiple assessment messages won't help me in this case, as it would show both messages regardless of the answer to 11111X2X3

If 11111X2X3 = YES adds 10 points and NO adds 0 points, you will still end up at 100+ and get the assessment message. You have no way to have a message display based on a single answer.

In a nutshell, if assessment score >X and answer to 11111X2X3 = YES I want to display one message, and if 11111X2X3 = NO I want to display something different.

I imaging some Javascript is necessary in the assessment message, but I need to be able to access the answer to a specific question.
Last Edit: 6 years 1 week ago by thaJack. Reason: Clarification

6 years 1 week ago #56771 by Mazi

thaJack wrote: If 11111X2X3 = YES adds 10 points and NO adds 0 points, you will still end up at 100+ and get the assessment message. You have no way to have a message display based on a single answer.

That is not true. You can add 1000 point if the answer to question X is yes and you set a second assessment with MAX=1150 this second message should only show up if the question was answered "yes".

You set need to set scores and limits carefully.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

6 years 1 week ago #56778 by thaJack
I have multiple answers within the survey that add 150 to the assessment value. The number of those could change from day to day.

Essentially what I'm doing is trying to set a "trigger." If any of the "trigger" answers are selected during the survey I want it to tell the person "XYZ" at the end. If none of the triggers are hit, I want it to say "ABC" at the end.

However, if none of the triggers were hit, and the answer to question 11111X2X3 = "YES" then I want it to tell them "DEF" in addition to "ABC".

I may submit this as a feature, but it would be neat if the assessment values on answers accepted three different things:

"+10": would add 10 to the assessment score.
"-10": would subtract 10 from the assessment score.
"10" or "=10": would set the assessment score to 10.

So maybe if they answered the first question with an answer set to "+10" it would make their assessment score "10". Then, on the next question the value was "-5", it would bring their total back down to "5". Then, on the third question they hit one where the assessment value is "50", it would make their total "50".

I would love to be able to set the assessment value to something rather than adding/subtracting it every time.

This way, I could have all of my triggers set to "=150" and if they hit any of them, no matter how many, I would know that at the end the assessment would result in "150".

Additionally, it would be nice to be able to have the assessment score a condition of a question. For example, only show this question if the running assessment score is ">=100".

6 years 1 week ago - 6 years 1 week ago #56799 by tpartner
I think the only way to accomplish this is to use JavaScript and a cookie to pass the value of question 11111X2X3 into the end page and then display message "DEF" accordingly.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 6 years 1 week ago by tpartner.

6 years 1 week ago #56802 by thaJack
Is that something easy to do?

6 years 1 week ago #56839 by Mazi

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

6 years 1 week ago - 6 years 1 week ago #56853 by tpartner

Is that something easy to do?

It's not hard. The following example stores the answer to a Yes/No question in a cookie and then only displays the end message if that answer is "Yes".

1) Set up your survey to use JavaScript .

2) Add the following to the source of a question (or question help) in the last page of the survey. Replace "11111X22X33" with the SGQA of a Yes/No question on a previous page. The script will create a cookie with the answer of the Yes/No.
```<script type="text/javascript" charset="utf-8">

})

</script>```

3) Create your dynamic end message and wrap it in a span element that can be dynamically hidden and shown. In the source of the end messsage, add something like:
`<span class="dynamicMessage">Some end message that is only displayed if the yes/No question is "Yes".</span>`

4) Also in the source of the end messsage, add the following script. It will initially hide the end message and then retrieve the cookie. If the cookie value is "Yes" the end message will be displayed.
```<script type="text/javascript" charset="utf-8">

// A function to get the value of a cookie by name

if (results) {
return (unescape (results[2]));
}
else {
return null;
}
}

// Hide the dynamic message
\$('.dynamicMessage').hide();

// Display the message if the answer is "Yes"
\$('.dynamicMessage').show();
}

});

</script>```

So, this should let you display assessment messages with a dynamic end message under them.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 6 years 1 week ago by tpartner.

6 years 1 week ago #56865 by thaJack
Could I use two variables in the same cookie on two different questions? For example:

<code>
</code>

in one question and then...

<code>
</code>

In a second question? Would I query them the same way on my assessment result page? I only want to show the dynamic message, for example, if both questions are YES.

I would do (if... and... else), obviously. But they could be stored in the same cookie?

6 years 1 week ago #56872 by tpartner
You could store them in the same cookie but I think that would over-complicate things. If you only want to show the message if both questions are "Yes", I would check them before storing the cookie and then set the cookie to "Show" or "Hide".

So your script for the last page would be something like:
```<script type="text/javascript" charset="utf-8">

// Find the question results
var result1 = '{INSERTANS:11111X22X33}';
var result2 = '{INSERTANS:11111X22X34}';

// Set a cookie with the Show/Hide value
if(result1 == "Yes" && result2 == "Yes") {
else {
}

})

</script>```

And in the end message:
```<script type="text/javascript" charset="utf-8">

// A function to get the value of a cookie by name

if (results) {
return (unescape (results[2]));
}
else {
return null;
}
}

// Hide the dynamic message
\$('.dynamicMessage').hide();

// Display the message if the cookie is "Show"
if(showMsg == 'Show') {
\$('.dynamicMessage').show();
}

});

</script>```

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.