Check out the LimeSurvey source code on GitHub!

use radio button to load next question?

More
5 years 6 months ago #64396 by badronald
Basically we would display each question, one at a time, in a box As the participant clicks Yes or No to each item, a box refreshes with the next item. If they say Yes, the sub-question, (if applicable) would appear.

I am trying to do this on one page instead of a page by page as these are part of a larger survey and the number of page loads would be quite large.

I was thinking javascript?

Please Log in to join the conversation.

More
5 years 6 months ago #64414 by tpartner
You can use conditions to dynamically show/hide questions as others are answered - docs.limesurvey.org/Setting+conditions&s...tions+for+LimeSurvey

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 6 months ago #64418 by badronald
Right, but can you use conditions to hide the first question and show the next question?
so
Show Q1
Participant Answers Q1
Hide Q1

Show Q2

Participant Answers Q2

Hide Q2

Show Q3

and so on

?

Please Log in to join the conversation.

More
5 years 6 months ago #64421 by tpartner
Oh, now I get what you're trying to do.

In this case you'll need to use JavaScript to show/hide the questions as you proceed.

The details of the script would depend on question types and sequence.

Are all questions select-one radios?

Do you care that respondents won't be able to modify previous answers?

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 6 months ago #64425 by badronald
:)
They are all Yes/No Questions
I do know the javascript for show/hide divs. for this but having some difficulty putting it in limesurvey. Was hoping there was an easier way.

Please Log in to join the conversation.

More
5 years 6 months ago #64614 by TMSWhite
You are right that the JavaScript for showing, hiding, reseting, etc. each question type can be tricky. I've documented some of the JQuery for showing/hiding here .

It shouldn't be too hard to add show(question) and hide(question) functions to Expression Manager , which is available now in a dev branch and will be incorporated into LimeSurvey 1.92. FYI, Showing and Hiding questions is separable from whether they are relevant, so it is possible to hide questions without NULLing their values.

Please Log in to join the conversation.

More
5 years 6 months ago #64625 by tpartner
If all questions are radios and the behaviour you want is:
- Initially hide all questions
- Show the first question
- When a radio is clicked, that question is hidden and the next is shown

1) Set up your survey to use JavaScript .

2) Add the following script to the source of one of the questions.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Add a class to all questions and hide them
		$('div[id^="question"]').addClass('questionDiv').hide();
 
		// Show the first question
		$('.questionDiv:first').show();
 
		// A listener on the radios to hide the
		// clicked question and show the next question
		$('input.radio, label').click(function(){
			if($(this).parents('.questionDiv').next('.questionDiv').length > 0) {
				$(this).parents('.questionDiv').hide();
				$(this).parents('.questionDiv').next('.questionDiv').show();
			}
		});
 
	});
 
</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.

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