Welcome, Guest
Username: Password: Remember me

TOPIC: use radio button to load next question?

use radio button to load next question? 2 years 8 months ago #64396

  • badronald
  • badronald's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 47
  • Karma: 0
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?
The administrator has disabled public write access.

Re: use radio button to load next question? 2 years 8 months ago #64414

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3837
  • Thank you received: 688
  • Karma: 330
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.

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: use radio button to load next question? 2 years 8 months ago #64418

  • badronald
  • badronald's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 47
  • Karma: 0
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

?
The administrator has disabled public write access.

Re: use radio button to load next question? 2 years 8 months ago #64421

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3837
  • Thank you received: 688
  • Karma: 330
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.

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: use radio button to load next question? 2 years 8 months ago #64425

  • badronald
  • badronald's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 47
  • Karma: 0
:)
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.
The administrator has disabled public write access.

Re: use radio button to load next question? 2 years 8 months ago #64614

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
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.
The administrator has disabled public write access.

Re: use radio button to load next question? 2 years 8 months ago #64625

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3837
  • Thank you received: 688
  • Karma: 330
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.115 seconds
Donation Image