• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Count number of checked elements in checkbox group

Count number of checked elements in checkbox group 8 years 10 months ago #35267

  • jurgeng
  • jurgeng's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 10
Hi,

I need a way to count how many elements are selected in a checkbox group.

I have a form where a person has to pay a different price depending on how many items are selected (spread over multiple groups). E.g. participants pay per module. There's a checkbox group with available dates for ballet and a one with available dates for jazz.

They could f.e. select 2 sessions on ballet and 1 session on jazz dance (counter = 3), or 1 on ballet and 1 on jazz (counter = 2), or 2 on ballet (counter = 2)... or even just one single session (counter = 1).

So if you could help me out with the formula for counting the number of selected items...
Standing on the shoulders of giants, enjoying the view.
The administrator has disabled public write access.

Count number of checked elements in checkbox group 8 years 10 months ago #35317

  • jurgeng
  • jurgeng's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 10
Okay... so I got some feedback from the support staff that I will have to use some Javascript to make this happen. It's not possible with the settings, calculated fields, ...

As my site already uses jQuery, I decided to make advantage of this. Apart from that, I noticed that jQuery was in no-conflict mode. This means that I shouldn't use $(...) as my starting point, but replace it with jQuery(...).

So I figured it out, and I'd like to share it with the lot of you...
Here goes:

1. I added the attribute class="course" to every checkbox that should be counted
2. I created a text field with id "counter" in which I want the value of the count to appear.
3. In the form properties > CSS and Javascript, I added this code to the Javascript section:
<script>
jQuery(document).change(function() {
  var n = jQuery( "input.lesson:checked" ).length;
  jQuery( "input#counter" ).val(n);
});
</script>
Standing on the shoulders of giants, enjoying the view.
Last Edit: 8 years 10 months ago by jurgeng. Reason: added information
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!