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

TOPIC: auto select options when "all" is checked?

auto select options when "all" is checked? 3 years 1 month ago #62301

  • elduce
  • elduce's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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
The administrator has disabled public write access.

Re: auto select options when "all" is checked? 3 years 1 month ago #62305

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
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.

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: auto select options when "all" is checked? 3 years 1 month ago #62321

  • elduce
  • elduce's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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!
The administrator has disabled public write access.

Re: auto select options when "all" is checked? 3 years 1 month ago #62322

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
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.

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: auto select options when "all" is checked? 3 years 1 month ago #62324

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
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.
spans_1.png


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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: elduce

Re: auto select options when "all" is checked? 3 years 1 month ago #62332

  • elduce
  • elduce's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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?
The administrator has disabled public write access.

Re: auto select options when "all" is checked? 3 years 1 month ago #62334

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
Untitled-2_2011-06-17.png
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: auto select options when "all" is checked? 3 years 1 month ago #62338

  • elduce
  • elduce's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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.
The administrator has disabled public write access.

Re: auto select options when "all" is checked? 3 years 1 month ago #62339

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
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.

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: auto select options when "all" is checked? 3 years 1 month ago #62407

  • elduce
  • elduce's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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.
spans_1.png


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
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.240 seconds
Donation Image