How to add a button to make the same selection for all questions

More
1 month 3 weeks ago #159057 by lintu
lintu created the topic: How to add a button to make the same selection for all questions
Hello Folks,

I have a survey with 90 questions with each having 5 answers with radio buttons for making a selection. I would like to place a button at the very top of the survey and make it easy for the survey takers to make the same selection (pick 1 radio button out of the 5) for the 90 questions.

Is this possible with LimeSurvey and if so, please guide me on how to achieve this. Thanks in advance for your help.

Please Log in to join the conversation.

More
1 month 3 weeks ago #159062 by Joffm
Joffm replied the topic: How to add a button to make the same selection for all questions
Hello, lintu,

my quick and dirty solution:

Place a first question - equal to the others.
With a - very long - equation put the answer to this question into all others.

Best regards
Joffm

Please Log in to join the conversation.

More
1 month 3 weeks ago #159064 by lintu
lintu replied the topic: How to add a button to make the same selection for all questions
Hi Joffm,

Thanks for your quick response. Will your suggestion work if I have the questions in multiple pages (as part of different groups)?

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #159067 by Joffm
Joffm replied the topic: How to add a button to make the same selection for all questions
Hi, lintu
{Q2=if(Q1==1,1,if(Q1==2,2,3))} works if equation and Q2 are in one group and Q1 is in a different group.

The other way - just try.

If not: Set an equation at the beginning of each group.

Best regards
Joffm
Last Edit: 1 month 3 weeks ago by Joffm.

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #159111 by lintu
lintu replied the topic: How to add a button to make the same selection for all questions
I used the following code within the question source and it worked. I am able to use the selection for a question answer to set the remaining questions radio button choices:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
     // Find the checked option for question code G2Q1N
     var qc = '{G2Q1N}';
 
    if(qc == "1"){
        document.getElementById('answer{SID}X{GID}X{QID}SQ001-A1').checked = true;   
    }else if(qc == "2"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A2").checked = true;      
    }
        else if(qc == "3"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A3").checked = true;    
    }
        else if(qc == "4"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A4").checked = true;   
    }
        else if(qc == "5"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A5").checked = true;     
    }
});
</script>
 

I would hate to copy/paste this code in 90+ questions, so I added it to the script/template.js file. But the code does not work there - it is not able to find the selection for question code G2Q1N and gives a 'Undefined variable' error. What is the proper way to find the selected choose for the radio button on question code G2Q1N?

Thanks!!
Last Edit: 1 month 3 weeks ago by lintu.

Please Log in to join the conversation.

More
1 month 3 weeks ago #159116 by tpartner
tpartner replied the topic: How to add a button to make the same selection for all questions
You cannot access Expression Manager variables directly from template.js. I suppose you could place that script in question.pstpl but you would need to add some sort of condition to ensure it only affects the appropriate questions.

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
1 month 3 weeks ago #159117 by tpartner
tpartner replied the topic: How to add a button to make the same selection for all questions
...maybe adding a question class to the appropriate questions and then something like this:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		if($('#question{QID}').hasClass('my-class') {
			 // Find the checked option for question code G2Q1N
			 var qc = '{G2Q1N}';
 
			if(qc == "1"){
				document.getElementById('answer{SID}X{GID}X{QID}SQ001-A1').checked = true;   
			}else if(qc == "2"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001-A2").checked = true;      
			}
				else if(qc == "3"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001-A3").checked = true;    
			}
				else if(qc == "4"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001-A4").checked = true;   
			}
				else if(qc == "5"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001-A5").checked = true;     
			}
		}
	});
</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.

More
1 month 3 weeks ago #159118 by tpartner
tpartner replied the topic: How to add a button to make the same selection for all questions
...and, maybe this to shorten it a bit...

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		if($('#question{QID}').hasClass('my-class') {
			 // Find the checked option for question code G2Q1N
			 var qc = '{G2Q1N}';
 
			 // Check the corresponding option here
			 $('#answer{SID}X{GID}X{QID}SQ001-A'+qc).prop('checked', true);
		}
	});
</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.

More
1 month 3 weeks ago - 1 month 3 weeks ago #159119 by lintu
lintu replied the topic: How to add a button to make the same selection for all questions
Hello Tony,

Thank you very much for helping me out with a code snippet. I checked the LimeSurvey manual and found the full list of question classes. The class for Array (5 point choice) is '.array-5-pt' which I used in the code below:
<script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
    	if($('#question{QID}').hasClass('.array-5-pt') {
			 // Find the checked option for question code Q1
			 var qc = '{Q1}';
 
			 // Check the corresponding option here
			 $('#answer{SID}X{GID}X{QID}SQ001-A'+qc).prop('checked', true);
		}
	});
</script>

I inserted this piece of code at the beginning of question.pstpl but it's not working - I'll keep looking into what's wrong. I have attached my test survey and test template to this post if you want to try it out on your end.
Attachments:
Last Edit: 1 month 3 weeks ago by lintu.

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #159120 by lintu
lintu replied the topic: How to add a button to make the same selection for all questions
A quick update: I found that my original code below works by placing it in template/question.pstpl if the question type is '5 point choice' but does not work when it's an 'array'. It is throwing an "undefined variable" error on the question code. How do I resolve this?
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
     // Find the checked option for question code G2Q1N
     var qc = '{G2Q1N}';
 
    if(qc == "1"){
        document.getElementById('answer{SID}X{GID}X{QID}SQ001-A1').checked = true;   
    }else if(qc == "2"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A2").checked = true;      
    }
        else if(qc == "3"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A3").checked = true;    
    }
        else if(qc == "4"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A4").checked = true;   
    }
        else if(qc == "5"){
        document.getElementById("answer{SID}X{GID}X{QID}SQ001-A5").checked = true;     
    }
});
</script>
 

Thanks
Last Edit: 1 month 3 weeks ago by lintu.

Please Log in to join the conversation.

More
1 month 3 weeks ago #159121 by lintu
lintu replied the topic: How to add a button to make the same selection for all questions
Solved the problem by changing var qc = '{G2Q1N}'; to var qc = '{G2Q1N_SQ001}';

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!