Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Condition on subquestion

Condition on subquestion 4 years 8 months ago #61763

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
I have a 'Multiple options with comments' with 10 sub questions. I want the last 3 sub-questions only to appear if a certain condition in the tokens are met.

Is this possible?
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 4 years 8 months ago by waitz.
The administrator has disabled public write access.

Condition on subquestion 4 years 8 months ago #61786

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5419
  • Thank you received: 1155
  • Karma: 480
1) Set up your survey to use JavaScript.

2) Add the following script to the source of the multiple choice question. Replace "QQ" with the multiple choice question question ID.

The script initially hides the last number of rows defined by the "hideNum" variable. If the Attribute 1 token equals "x", the rows are shown.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// The question ID and number of rows to be hidden
		var qID = QQ;
		var hideNum = 3;
 
		var listLength = $('#question'+qID+' li[id^="javatbd"]').length;
 
		// Loop through the options and hide the last n
		$('#question'+qID+' li[id^="javatbd"]').each(function(i){
 
			if (i >= listLength - hideNum) {
				$(this).addClass('dynamic').hide();
			}
  		});
 
		// Show the last n rows if token value is correct
		if('{TOKEN:ATTRIBUTE_1}' == 'x') {
			$('.dynamic').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.

Condition on subquestion 4 years 8 months ago #61828

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Fantastic, I will try it out. And then, the next step:

Can I, using a similar js approach, make a sub question required or not based on whether a token is empty or not?

Appreciate your expertise!!
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Condition on subquestion 4 years 8 months ago #62059

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Well, this wasn't so easy as I hoped. I have crunched my brain for a few days, and realize that there is more to it....

This is my challenge:

I use Tokens to display information I have about the user:


Then I ask the question: Is this information correct? If not, the user get the sub questions in a Multiple options with comments to change the fields which are not correct:





What I desperately need is the following:
  1. If e.g. (TOKEN:ATTRIBUTE_10) is blank, then hide the whole table row where this token appears in the question (2nd home phone).

  2. If then (TOKEN:ATTRIBUTE_10) is blank, then hide this subquestion in the Multiple options with comments.



I have ended up making tons of scenarios, and if this code above is possible, it would make the world incredibly better.

Is there anyone who know what to do?
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 4 years 8 months ago by waitz.
The administrator has disabled public write access.

Condition on subquestion 4 years 8 months ago #62099

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5419
  • Thank you received: 1155
  • Karma: 480
This is possible with JavaScript but it's complicated a little by the fact that your token use is not sequential.

The method for hiding the rows in Q1 would depend on how you have created that question.

Can you attach a sample survey with these questions and a sample token table to test?
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.

Condition on subquestion 4 years 8 months ago #62113

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Sure, I have attached the survey, and the tokens.

As you can see, there are 2 question groups which are called Name and Address, because if some specific tokens are not present in the token table (which are imported through an xml file, and the token content varies), I don't want to present the whole table, as the first Name and Address group. Therefore I have a second Name and Address with less token information.

And here is where I would like to use a javascript method instead.

Rajan

PS: I am good with CSS, but javascript is above my current knowledge. So if it is complicated, I am open to hire your programming skills to help me with this...?
Attachments:
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 4 years 8 months ago by waitz.
The administrator has disabled public write access.

Condition on subquestion 4 years 8 months ago #62121

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 83
  • Karma: 37
Waitz-

We're working on a generic, non-JavaScript-dependent, solution to issues like the one you've described. Please comment on this thread if there is functionality we've missed.

The way I've tackled this sort of thing in the past was to:
(1) Show a table of the data I had, as separate questions with a template to make it look like a table, and use check box (as you have done) to let users indicate they needed to edit it
(2) One next page (group), only display value-correction boxes for fields that were either missing or flagged as needing to be fixed on prior page
(3) Make the sub-questions conditional on the other entered values. I've never had access to Matrix-style questions before, so I'm still learning the nuances of their conditional display, but sounds like there would be demand for such a feature.

/Tom
The administrator has disabled public write access.

Condition on subquestion 4 years 8 months ago #62139

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5419
  • Thank you received: 1155
  • Karma: 480
Okay, this is going to require a few steps but is doable.

For simplicity's sake, let's call the yes/no question Q1 and the multiple-options-with-comments question Q2.

1) Add token-related classnames to all of the relevant table rows in Q1. So the source of Q1 should look something like this:

2) Wrap all of the Q2 sub-questions in spans with token-related classnames. So they should look something like this:

3) Add the following script to the source of the group description. The script assigns the span classnames to their parent list item(row) and then checks the values of the relevant token attributes. If an attribute is found empty, the corresponding rows in Q1 and Q2 are hidden.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		// Add a class to all of the multi-opt rows
		$('.multiple-opt-comments li[id^="javatbd"] .option label span').each(function(i){	
			$(this).parents('li:eq(0)').addClass($(this).attr('class'));
  		});
 
		// And now a bunch of ugly conditionals
		if(!'{TOKEN:FIRSTNAME}') {$('.FIRSTNAME').hide();}
		if(!'{TOKEN:LASTNAME}') {$('.LASTNAME').hide();}
		if(!'{TOKEN:EMAIL}') {$('.EMAIL').hide();}
		if(!'{TOKEN:ATTRIBUTE_2}') {$('.ATTRIBUTE_2').hide();}
		if(!'{TOKEN:ATTRIBUTE_3}') {$('.ATTRIBUTE_3').hide();}
		if(!'{TOKEN:ATTRIBUTE_4}') {$('.ATTRIBUTE_4').hide();}
		if(!'{TOKEN:ATTRIBUTE_5}') {$('.ATTRIBUTE_5').hide();}
		if(!'{TOKEN:ATTRIBUTE_6}') {$('.ATTRIBUTE_6').hide();}
		if(!'{TOKEN:ATTRIBUTE_7}') {$('.ATTRIBUTE_7').hide();}
		if(!'{TOKEN:ATTRIBUTE_8}') {$('.ATTRIBUTE_8').hide();}
		if(!'{TOKEN:ATTRIBUTE_9}') {$('.ATTRIBUTE_9').hide();}
		if(!'{TOKEN:ATTRIBUTE_10}') {$('.ATTRIBUTE_10').hide();}
		if(!'{TOKEN:ATTRIBUTE_11}') {$('.ATTRIBUTE_11').hide();}
		if(!'{TOKEN:ATTRIBUTE_12}') {$('.ATTRIBUTE_12').hide();}
		if(!'{TOKEN:ATTRIBUTE_13}') {$('.ATTRIBUTE_13').hide();}
		if(!'{TOKEN:ATTRIBUTE_14}') {$('.ATTRIBUTE_14').hide();}
		if(!'{TOKEN:ATTRIBUTE_15}') {$('.ATTRIBUTE_15').hide();}
 
	});
 
</script>

Here is a copy of your survey with the changes described above applied to the group I've renamed "Name and Address 2". You will find the JavaScript in the group description source. In this group I also modified the conditions on Q2 a bit to show the question appropriately (copied all Q1 questions to Q2 and added "if Q1 = No" o each scenario).

I have made no changes to the "Name and Address 1" or any other groups.

limesurvey_survey_64197_TONY.lss
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.

Condition on subquestion 4 years 8 months ago #62140

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5419
  • Thank you received: 1155
  • Karma: 480
Hmm... the survey didn't attach so here:

File Attachment:

File Name: survey.zip
File Size:35 KB
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.
Last Edit: 4 years 8 months ago by tpartner.
The administrator has disabled public write access.

Condition on subquestion 4 years 8 months ago #62162

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
WOW, Tony. That was incredibly valuable!!! Thank you very much. It works perfectly and it has reduced the complexity of the survey quite a lot.

Since I see you're part of the LimeSurvey team, I just made a donation. Hope that's OK.

Rajan
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Condition on subquestion 4 years 7 months ago #62169

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5419
  • Thank you received: 1155
  • Karma: 480
You're welcome and thanks for the donation.

Although the members of the LimeSurvey team are volunteers, these donations are needed to pay for servers, etc to keep the project alive.
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.

Condition on subquestion 3 years 7 months ago #82053

  • arielmosto
  • arielmosto's Avatar
  • Offline
  • Junior Lime
  • Posts: 33
  • Karma: 0
Hi!
I need to do the same but with the kind of question multiple-opt. (No multiple-opt-comments). Probe and using this code for multiple-opt it does not work, displays the check box. Thank you! Ariel
The administrator has disabled public write access.

Condition on subquestion 3 years 7 months ago #82062

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5419
  • Thank you received: 1155
  • Karma: 480
Try this:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		// Add a class to all of the multi-opt rows
		$('.multiple-opt li[id^="javatbd"] .option label span').each(function(i){	
			$(this).parents('li:eq(0)').addClass($(this).attr('class'));
  		});
 
		// And now a bunch of ugly conditionals
		if(!'{TOKEN:FIRSTNAME}') { $('.FIRSTNAME').hide(); }
		if(!'{TOKEN:LASTNAME}') { $('.LASTNAME').hide(); }
		if(!'{TOKEN:EMAIL}') { $('.EMAIL').hide(); }
		if(!'{TOKEN:ATTRIBUTE_2}') { $('.ATTRIBUTE_2').hide(); }
		if(!'{TOKEN:ATTRIBUTE_3}') { $('.ATTRIBUTE_3').hide(); }
		if(!'{TOKEN:ATTRIBUTE_4}') { $('.ATTRIBUTE_4').hide(); }
		if(!'{TOKEN:ATTRIBUTE_5}') { $('.ATTRIBUTE_5').hide(); }
		if(!'{TOKEN:ATTRIBUTE_6}') { $('.ATTRIBUTE_6').hide(); }
		if(!'{TOKEN:ATTRIBUTE_7}') { $('.ATTRIBUTE_7').hide(); }
		if(!'{TOKEN:ATTRIBUTE_8}') { $('.ATTRIBUTE_8').hide(); }
		if(!'{TOKEN:ATTRIBUTE_9}') { $('.ATTRIBUTE_9').hide(); }
		if(!'{TOKEN:ATTRIBUTE_10}') { $('.ATTRIBUTE_10').hide(); }
		if(!'{TOKEN:ATTRIBUTE_11}') { $('.ATTRIBUTE_11').hide(); }
		if(!'{TOKEN:ATTRIBUTE_12}') { $('.ATTRIBUTE_12').hide(); }
		if(!'{TOKEN:ATTRIBUTE_13}') { $('.ATTRIBUTE_13').hide(); }
		if(!'{TOKEN:ATTRIBUTE_14}') { $('.ATTRIBUTE_14').hide(); }
		if(!'{TOKEN:ATTRIBUTE_15}') { $('.ATTRIBUTE_15').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.

Condition on subquestion 3 years 7 months ago #82064

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
1. Which Limesurvey version do you use?

2. Please post a link to an activated sample survey.

3. Please post the code you are using.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Condition on subquestion 3 years 7 months ago #82080

  • arielmosto
  • arielmosto's Avatar
  • Offline
  • Junior Lime
  • Posts: 33
  • Karma: 0
Thanks !



/* DEFINED ABOVE UNDER "General list styles" - - - - -
.multiple-opt
*/

You have this ones:

.multiple-opt-comments ul,.multiple-short-txt ul,.numeric-multi ul {
display: table;
padding: 0%;
margin: 1em;

.multiple-opt-comments ul li,.multiple-short-txt ul li,.numeric-multi ul li
{
display: table-row;


.multiple-opt-comments ul li span.option {
display: table-cell;
vertical-align: baseline;
}




My version its 1.92 thank you very much !
Last Edit: 3 years 7 months ago by arielmosto.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.222 seconds