select max checkbox limesurvey

More
3 years 11 months ago #95157 by mattias01
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.

Please Log in to join the conversation.

More
3 years 11 months ago #95158 by holch
There is already a maximum answers function included in limesurvey.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
3 years 11 months ago #95159 by mattias01
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.

Please Log in to join the conversation.

More
3 years 11 months ago #95183 by tpartner
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.

Please Log in to join the conversation.