Check out the LimeSurvey source code on GitHub!

Conditional Help

More
5 years 2 months ago #70995 by thedead
Hi There,

I'm wondering if it's possible to show the help only if they select a response on a yes/no question.

Thanks

Please Log in to join the conversation.

More
5 years 2 months ago #71007 by tpartner
You can use JavaScript to do this. Which answer do you want to display the help?

Alternatively, you could use conditions to show a text-display question based on the answer to the yes-no question.

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 2 months ago #71020 by thedead
I tried the conditions/text, but i feel it isn't as clean looking.

On a yes no question, if the answer is 'yes' how could I use JS to show the help?

If you show me once, I should be able to adapt it for 'no' and other question types.

Thanks!

Please Log in to join the conversation.

More
5 years 2 months ago #71034 by tpartner
1) Set up your survey to use JavaScript .

2) Add the following script to the source of the question.

3) Replace "QQ" with the question ID .

4) Replace "Y" with "N" (or another answer code) to have another answer show the help element

5) If necessary, modify ".survey-question-help" when using other templates (this example is for the default template)

The script hides the help element of a question and toggles its display depending on whether a certain answer is selected.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		// Call the function with the question ID and the answer code to show help
		showHelp(QQ, 'Y')
 
		function showHelp(qID, answerCode) {
 
			// Define the question help element (may need a different selector for other templates)
			var helpElement = $('#question'+qID+' .survey-question-help');
 
			// Hide the help
			$(helpElement).hide();
 
			$('#question'+qID+' input.radio').click(function(el){
				if($(this).attr('value') == answerCode) {
					$(helpElement).show();
				}
				else {
					$(helpElement).hide();
				}
			});
		}
	});
 
</script>

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 2 months ago #71039 by thedead
Thanks! Works great

Please Log in to join the conversation.

More
5 years 2 months ago #71041 by TMSWhite
thedead-

In Version 1.92 and beyond, you can use an Expression Manager (EM) equation to control the visibility of text in the Help section, but not to turn on/off the Help icon, so tpartner's solution is currently more elegant.

Say your question is QQ, you'd have the text of help say this:
{if(QQ=='Y','Here is the help message I would like to show if QQ is Yes','')}

Then EM would make that text appear/disappear as needed.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form