Hide array cells with condition

Mehr
1 Jahr 3 Monate her - 1 Jahr 3 Monate her #167572 von AlessandraAndreotti
Hi!

I need to hide some cells of the array B based on the answer in the array A.

For example, if question Q001 of the array A is not answered, so the question Q001 of the array B must be hide.

Thanks in advance.
Letzte Änderung: 1 Jahr 3 Monate her von AlessandraAndreotti.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

LimeSurvey Partners
Mehr
1 Jahr 3 Monate her #167576 von Joffm
Hi, Alessandra,

you are not very clear.
You say you would like

to hide some cells of the array B


But here it seems you want to hide some subquestions

the question Q001 of the array B must be hide


Well, assuming you use a "normal" arrayA with subquestions "SQ001", "SQ002", ...
This array seems to be "not mandatory", because you say

if question Q001 of the array A is not answered

.

Now you already know the relevance equation of the subquestions of arrayB
!is_empty(arrayA_SQ001)
!is_empty(arrayA_SQ002)
...
meaning: the subquestions of arrayB are only displayed if this subquestion in arrayA is NOT empty.



Joffm

P.S. If the "not answered" means that the respondent clicked "not answered" it's a bit different:
arrayA_SQ001!=[code_no_answer]


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Anhänge:

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 3 Monate her #167601 von AlessandraAndreotti
Hi Joffm,
thanks for your prompt reply.
I've explained myself badly.
In attachment you can find my LimeSurvey example.

I need that subquestion D2_D2Y1xD2X1 on page2 to be hidden if subquestion D1_D1Y1xD1X1 is not answered.

In the attached images, I've circled in red the subquestion that must be hidden on page 2.

Thanks in advance.
Alessandra
Anhänge:

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 3 Monate her #167624 von tpartner
As far as I know, the only way to do that would be with JavaScript.

Do you need it for all cells in the second array?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 3 Monate her - 1 Jahr 3 Monate her #167625 von AlessandraAndreotti
Hi tpartner,
thank you for the reply.

Yes, I need it for all cells in the second array.

I've found the following Java script in the web, but I don't be able to adapt it for my necessity.


<script type="text/javascript" charset="utf-8">

$(document).ready(function() {

$('input[name="69965X2X10SQ001_SQ001"]').attr('disabled', 'disabled');

});

</script>

I don't know if it is the correct java script...
Thanks for your help in advance.
Alessandra
Letzte Änderung: 1 Jahr 3 Monate her von AlessandraAndreotti.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 3 Monate her #167637 von tpartner
1) Place something like this in the source of the second array. It will render a hidden array of all answered Q1 sub-question codes that we can access with JavaScript.

<div class="hidden equation">
	{implode(',', if(D1_D1Y1_D1X1 == '1', 'D1Y1_D1X1', ''), if(D1_D1Y1_D1X2 == '1', 'D1Y1_D1X2', ''), if(D1_D1Y1_D1X3 == '1', 'D1Y1_D1X3', ''), if(D1_D1Y2_D1X1 == '1', 'D1Y2_D1X1', ''), if(D1_D1Y2_D1X2 == '1', 'D1Y2_D1X2', ''), if(D1_D1Y2_D1X3 == '1', 'D1Y2_D1X3', ''), if(D1_D1Y3_D1X1 == '1', 'D1Y3_D1X1', ''), if(D1_D1Y3_D1X2 == '1', 'D1Y3_D1X2', ''), if(D1_D1Y3_D1X3 == '1', 'D1Y3_D1X3', ''), if(D1_D1Y4_D1X1 == '1', 'D1Y4_D1X1', ''), if(D1_D1Y4_D1X2 == '1', 'D1Y4_D1X2', ''), if(D1_D1Y4_D1X3 == '1', 'D1Y4_D1X3', ''))}
</div>


2) Add this script to the source of Q2. It will loop through that hidden array and disable Q2 sub-questions if the corresponding Q1 sub-question was not answered.

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		var q1Code = 'D1';
		var q2Code = 'D2';
		var answeredQ1 = $.trim($('#question{QID} .hidden.equation:eq(0)').text()).split(',');
 
		// Loop through answers from Q1 and add classes to the corresponding Q2 inputs
		$.each(answeredQ1, function(i, val) {
			var re = new RegExp(q1Code, 'g');
			var q2CellCode = val.replace(re, q2Code);
			if(val != '') {
				$('#question{QID} input[type="text"][id$="'+q2CellCode+'"]').addClass('relevant');
			}
		});
 
		// Disable irrelevant items
		$('#question{QID} input[type="text"]:not(.relevant)').prop('disabled', true).val('');
 
 
	});
</script>





Here is your sample survey back with those modifications:

Dateianhang:

Dateiname: limesurvey...1921.lss
Dateigröße:24 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Anhänge:
Folgende Benutzer bedankten sich: AlessandraAndreotti

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 3 Monate her #167642 von AlessandraAndreotti
Thank you very much!
It works!

Best,
Alessandra

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha