Skip Navigation

[Resolved] limiting checkbox selections

This thread is resolved. Here is a description of the problem and solution.

Problem:
limiting checkbox selections on Forms

Solution:
You will have to add custom jQuery/Javascript code to count number of checkboxes options checked/selected and based on that you can limit the number of checkboxes allowed.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/limiting-checkbox-selections/#post-2092227

Relevant Documentation:

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by justinW-8 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2090911

I am trying to use this jquery to limit the result of a check box by a user to 5, I want to use the field as shown below and I don't know what I am doing wrong because it is not working on the front end

jQuery(document).ready(function ($) {
var tema_limit = 5;

$('input:checkbox[name="checkboxes-wpcf-what-are-the-top-five-things-that-you-believe-your-community-offers-s[]"]').on('change', function(evt) {
if($('[name="tema[]"]:checked').length >= tema_limit) {
this.checked = false;
}
});
});

#2091197

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL and admin access details so I can check your code and adjust as required.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2091203

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems you forget to share problem URL where I can see the checkboxes you added and where you added the JS code you shared.

#2091755

hidden link
this is the form page
I added the code to the form editor in tool set for creating community

#2091757

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Unfortunately I could not able to login using the admin access details you shared. Can you please send me working admin access details.

I have set the next reply to private which means only you and I have access to it.

#2091789

the login url is hidden link

#2091807

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - I know the login URL but I still could not able to login using the admin access details (user / pass) you shared.

Can you please send me working admin access details.

I have set the next reply to private which means only you and I have access to it.

#2092227

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've adjust the code that will allow you to select five checkboxes at the moment. Here is the modified code:

jQuery(document).ready(function ($) {
var tema_limit = 6;
   
$('input:checkbox[name="wpcf-what-are-the-top-five-things-that-you-believe-your-community-offers-s[]"]').on('change', function(evt) {
    if($('[name="wpcf-what-are-the-top-five-things-that-you-believe-your-community-offers-s[]"]:checked').length >= tema_limit) {
       this.checked = false;
   }
});
});

Can you please confirm it works as expected: hidden link

#2094697

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.