Welcome, Guest
Username: Password: Remember me

TOPIC: select max checkbox limesurvey

select max checkbox limesurvey 1 year 4 months ago #95157

  • mattias
  • mattias's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 77
  • 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 1 year 4 months ago #95158

  • holch
  • holch's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2621
  • Thank you received: 307
  • Karma: 113
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 | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

select max checkbox limesurvey 1 year 4 months ago #95159

  • mattias
  • mattias's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 77
  • 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 1 year 4 months ago #95183

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.120 seconds
Donation Image