Skip Navigation

[Closed] Count checked input checkboxes in custom search by jquery?

This support ticket is created 2 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 3 voices.

Last updated by Luo Yang 2 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2314867

a.R

Hi there,

I´m using

 geklickt=$(".mainsearch .ethictopics").find('input[type=checkbox]:checked').length; 

to count the checked checkboxes.
But it always gives me the LAST value, BEFORE LAST CHANGE - no matter, if triggered
- by click on input or
- by SEARCH_RESULTS_UPDATED !

(On document ready, we do var geklickt=0;)

Is there something special about these checkboxes, that might interfere there?

#2315551

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

It might be the fact that the checkboxes are loaded via Ajax.

If that is the case, you need to also wrap your code into the ajaxComplete event:

$( document ).ajaxComplete(function() {
  geklickt =$(".mainsearch .ethictopics").find('input[type=checkbox]:checked').length;
});

I am not sure if the code above will work for your setting. I just wanted to give you an idea to wrap your code inside the ajaxComplete event.

For more information:

hidden link

If you need further assistance we will need to have a link that contain the checkboxes to tets ourselves.

Thank you.

#2315627

a.R

Thank you.

Unfortunately, this doesn´t do the trick. Still shows value BEFORE last change...

#2316003

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

As mentioned I will need the link to the page in question to be able to check and see how I can help.

Without having the access to the link that contains the checkboxes I am not sure how I can be of help.

Thanks.

#2316189

a.R

Oh, sorry.

Here we are: hidden link

Will you need an account to see enough?

Thanks, regards 🙂

#2316225

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the link. The link that you shared, does not have any "mainsearch" or "ethictopics" class. So the code will not work.

Please make sure that you select the correct wrapper item.

Thank you.

#2316551

a.R

Oh, sorry, that was really stupid. It should be:

$( document ).ajaxComplete(function() {
  geklickt = $( ".hauptsuche .ethikthemen" ).find( 'input[type=checkbox]:checked' ).length;
});

(I translated it for you, hoping you could better imagine what´s going on there.)

#2317011

Christopher Amirian
Supporter

Languages: English (English )

Screen Shot 2022-03-15 at 11.51.16.png

Hi there,

Thank you for the information. I checked and the issue that you have is a library of some sort that is used to hide the checkboxes and add some layer over that.

The problem is with that library. The same code works ok if you do as follows:

Remove this CSS code:

.sprachlevel input[type=checkbox] {display: none}

Or force it to show the original checkboxes.

Then you will see something like the image I attached.

If you check the original checkboxes that now show your code will work.

I checked the link below which is a normal Toolset search:

hidden link

There you can see that Toolset only uses a normal checkbox (Featured property search item). So the library is not part of Toolset.

Please remove the library you use for checkboxes and use what toolset provides to have a correct code execution.

Thank you.

#2320367

a.R

Hi, thank you.
Unfortunatley, removing that code line doesn´t have the desired effect for me.

#2324727

Hello,

Christopher is on holidays, I will take care of this ticket.

In your case, since it is a custom codes problem, please provide your website credentials in below private message box, also point out where I can edit your custom JS codes.

The topic ‘[Closed] Count checked input checkboxes in custom search by jquery?’ is closed to new replies.