Check out the LimeSurvey source code on GitHub!

auto select options when "all" is checked?

More
5 years 7 months ago #62301 by elduce
Hello,

I was wondering if there was a question type with multiple select options that can auto select multiple options when an "all" option is selected. I see that there's an exclude_all_others option but that basically does the opposite. You select an option and it disables all of the other options. What I'm looking to do is have an "All" option and when it's selected it selects a number of options. Hope there is! Any help would be greatly appreciated.

Thanks

Please Log in to join the conversation.

More
5 years 7 months ago #62305 by tpartner
There is no such question type or setting. You can add it to the feature requests - ideas.limesurvey.org/ .

In the meantime you can accomplish the effect with a little JavaScript. Do you want the first or last option to be "Select All"?

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 7 months ago #62321 by elduce

tpartner wrote: There is no such question type or setting. You can add it to the feature requests - ideas.limesurvey.org/ .

In the meantime you can accomplish the effect with a little JavaScript. Do you want the first or last option to be "Select All"?


Thanks for the response Tony. I'm looking for the first option to have a "Select defualt options" with a certain number of options checked and then also allow them to check some more options that aren't auto selected when they check the "select default options" option. Hope that made sense. Can you help me out with that? Thanks!

Please Log in to join the conversation.

More
5 years 7 months ago #62322 by tpartner
Okay, that's a little different from a "Check all" option. I'll have to give some thought to the easiest way to identify the "default" options.

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 7 months ago #62324 by tpartner
I think the easiest way to identify the "default" options would be to wrap them in spans with a class "defaultOpt". That way we can use JavaScript to detect those spans and manipulate their parents and siblings.

So your subquestions would look something like this. In this example the "default" options will be Option 2 and Option 3.

Then set up your survey to use JavaScript and add the following script to the source of the multiple options question. Replace "QQ" (line 7) with the multiple options question ID .

The script puts a listener on the first checkbox of the question that toggles the "default" options.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		// Fire the function allow checing of "default" options
		// Repeat this with as many question IDs as necessary
		setDefault(QQ);
 
		// The function
		function setDefault(qID) {
 
			// Assign classes to the "default" option rows
			$('#question'+qID+' .defaultOpt').each(function(i){
				$(this).parents('li:eq(0)').addClass('defaultParent');
			});
 
			// A listener on the first option to check/uncheck the "default" options
			$('#question'+qID+' input.checkbox:eq(0)').click(function(){
				if($(this).attr('checked') == true) {
					$('#question'+qID+' .defaultParent input.checkbox').attr('checked', true);
				}
				else {
					$('#question'+qID+' .defaultParent input.checkbox').attr('checked', false);
				}
			});
		}
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: elduce

Please Log in to join the conversation.

More
5 years 7 months ago #62332 by elduce
Thanks Tony,

I can't seem to be able to find this: "Go to global settings and set the setting 'XSS-Filter' to 'off'."

I looked all over the place but I am sleepy so maybe it's right in front of me?

Please Log in to join the conversation.

More
5 years 7 months ago #62334 by tpartner

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
5 years 7 months ago #62338 by elduce
I'm using Version 1.85+ (7593) am I out of luck? :(

Also when I try to reply to your posts it prompts me to login but it won't accept the password. I have to retrieve a new one to login. Then when I need to reply again it does the same exact thing.

Please Log in to join the conversation.

More
5 years 7 months ago #62339 by tpartner

I'm using Version 1.85+ (7593) am I out of luck?

No, you can set it in config.php by changing:
$filterxsshtml = true;
To:
$filterxsshtml = false;

If you don't have that line, add it to the end of the file.

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 #62407 by elduce

tpartner wrote: I think the easiest way to identify the "default" options would be to wrap them in spans with a class "defaultOpt". That way we can use JavaScript to detect those spans and manipulate their parents and siblings.

So your subquestions would look something like this. In this example the "default" options will be Option 2 and Option 3.



Then set up your survey to use JavaScript and add the following script to the source of the multiple options question. Replace "QQ" (line 7) with the multiple options question ID .

The script puts a listener on the first checkbox of the question that toggles the "default" options.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		// Fire the function allow checing of "default" options
		// Repeat this with as many question IDs as necessary
		setDefault(QQ);
 
		// The function
		function setDefault(qID) {
 
			// Assign classes to the "default" option rows
			$('#question'+qID+' .defaultOpt').each(function(i){
				$(this).parents('li:eq(0)').addClass('defaultParent');
			});
 
			// A listener on the first option to check/uncheck the "default" options
			$('#question'+qID+' input.checkbox:eq(0)').click(function(){
				if($(this).attr('checked') == true) {
					$('#question'+qID+' .defaultParent input.checkbox').attr('checked', true);
				}
				else {
					$('#question'+qID+' .defaultParent input.checkbox').attr('checked', false);
				}
			});
		}
	});
 
</script>


Thanks for your help. I've been working on this for a while and it doesn't seem to work. I added the javascript to the question source, added the question code to replace QQ, added the answers like you listed with the defaultOpt class. Nothing seems to happen. The ID to replace QQ is the questions code right? Hmmm

Please Log in to join the conversation.

More
5 years 6 months ago #62410 by tpartner

The ID to replace QQ is the questions code right?

No, it is the question ID:

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
5 years 6 months ago #62411 by holch

elduce wrote: Also when I try to reply to your posts it prompts me to login but it won't accept the password. I have to retrieve a new one to login. Then when I need to reply again it does the same exact thing.


Try to login via the front page. I have a similar problem (using Chrome) and whenever I am kicked out (for whatever reason), I can't use the login on the forum page, but have to go to the home page and login from there.

Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
5 years 6 months ago #62412 by elduce
ohhhh ok that's it. Now I see it works. This will be a huge help for what I'm trying to do. Thanks a bunch again.

Please Log in to join the conversation.

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