Welcome, Guest
Username: Password: Remember me

TOPIC: Conditional Help

Conditional Help 2 years 11 months ago #70995

  • thedead
  • thedead's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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
The administrator has disabled public write access.

Re: Conditional Help 2 years 11 months ago #71007

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4358
  • Thank you received: 826
  • Karma: 381
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Conditional Help 2 years 11 months ago #71020

  • thedead
  • thedead's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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!
The administrator has disabled public write access.

Re: Conditional Help 2 years 11 months ago #71034

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4358
  • Thank you received: 826
  • Karma: 381
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Conditional Help 2 years 11 months ago #71039

  • thedead
  • thedead's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
Thanks! Works great
The administrator has disabled public write access.

Re: Conditional Help 2 years 11 months ago #71041

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.157 seconds
Donation Image