Enable filters with javascript

Forums › Forums › Search & Filter Pro › Enable filters with javascript

Viewing 5 posts – 1 through 5 (of 5 total)
  • Anonymous
    #238846

    Hello,

    I’m trying to check radio buttons with a SVG map like this :

    const depts = document.querySelectorAll('#departements path');
    const form = document.querySelector('.searchandfilter');
    
    function handleDeptClick(e) {
        const departementNum = e.target.className.baseVal.split('-').pop();
        const inputRadioSelector = <code>input.sf-input-radio[value=&quot;${departementNum}&quot;]</code>;
        const inputRadio = document.querySelector(inputRadioSelector);
        if ( inputRadio.checked === false ) {
            inputRadio.checked = true;
        }
    }
    
    depts.forEach(dept => {
        dept.addEventListener('click', handleDeptClick);
    });

    this is working great,
    but I don’t know how to enable the filtering like this.
    If I try to submit the form, it reloads the page entirely.

    Thanks for any help on this,

    David

    Anonymous
    #238885

    Hello,

    maybe it would be better if I reformulate :
    what I’m trying to do is to trigger the filtering when changing the checked radio button with javascript.

    Thanks,

    David

    Trevor
    #238904

    In your code, I do not see how you are submitting the form. If the form is set to use Ajax, then it if you submit the form correctly, the page should not reload. This is a simply submit command:

    $('.searchandfilter').submit();

    Anonymous
    #238908

    Hello Trevor,

    thanks a lot ! it worked !

    I’m pretty sure I tried this before but in vanilla JS, not with JQuery.
    Maybe, this is why it didn’t work.

    Have a great day !

    David

    Trevor
    #238915

    Thanks for letting me know. I will close this thread for now.

Viewing 5 posts – 1 through 5 (of 5 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.