Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: select max checkbox limesurvey

select max checkbox limesurvey 3 years 7 months ago #95157

  • mattias01
  • mattias01's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
I made a function using jquery to limit the maximum responses on a checkbox but it does not work, I hope you can help me.
$(document).ready(function () {
   $("#answer58726X20219X218026").change(function () {
      var maxAllowed = 6;
      var cnt = $("#answer58726X20219X218026:checked").length;
      if (cnt > maxAllowed) 
      {
         $(this).prop("checked", "");
         alert('Select maximum ' + maxAllowed + ' technologies!');
     }
  });
});
 

regards.
The administrator has disabled public write access.

select max checkbox limesurvey 3 years 7 months ago #95158

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5432
  • Thank you received: 810
  • Karma: 240
There is already a maximum answers function included in limesurvey.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | [url=https://manual.limesurvey.org/Workarounds[/url]

If you found this answer helpful and it saved you some time please consider a [url=https://donate.limesurvey.org[/url] to the...
The administrator has disabled public write access.

select max checkbox limesurvey 3 years 7 months ago #95159

  • mattias01
  • mattias01's Avatar
  • Offline
  • Senior Lime
  • Posts: 79
  • Karma: 1
in the version I'm using has problems Version 1.91 + Build 11379, and I can not update so I try to do with jquery.
The administrator has disabled public write access.

select max checkbox limesurvey 3 years 7 months ago #95183

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
Try this. (replace "QQ" with the question ID)
$(document).ready(function(){
 
	// The question ID
	var qID = QQ;
 
	// Listener on the checkboxes
	$('#question'+qID+' .checkbox').change(function () {
		var maxAllowed = 6;
		var cnt = $('#question'+qID+' .checkbox:checked').length;
		if (cnt > maxAllowed) {
			$(this).attr('checked', false);
			alert('Select maximum ' + maxAllowed + ' technologies!');
		}
	});
});
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
Time to create page: 0.883 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form