select max checkbox limesurvey

More
4 years 2 months ago #95157 by mattias01
mattias01 created the topic: select max checkbox limesurvey
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
4 years 2 months ago #95158 by holch
holch replied the topic: select max checkbox limesurvey
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
4 years 2 months ago #95159 by mattias01
mattias01 replied the topic: select max checkbox limesurvey
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
4 years 2 months ago #95183 by tpartner
tpartner replied the topic: select max checkbox limesurvey
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.

Start now!

Just create your account and start using Limesurvey today.

Register now