Set default radio button with URL

Forums › Forums › Search & Filter Pro › Set default radio button with URL

Viewing 6 posts – 1 through 6 (of 6 total)
  • Anonymous
    #259186

    Hi!

    I want to be able to set the radio button in my filter with a parameter in the URL, which I did with this code:

    function getUrlVars() {
        var vars = {};
        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
            vars[key] = value;
        });
        return vars;
    }
    
    var animaltype = getUrlVars()["type"];
    console.log(animaltype);
    
    if(animaltype == 'cat'){
      $("input[value='Cat']").attr('checked', true);
    }
    

    It works and sets the radio button to cat, but it doesn’t actually change the results. What hook would I need to add to make that work? It’s clearly looking for the action of someone actually clicking on the button instead of just setting it to the option. Do you have any advice?

    Thank you for your help!!

    Kristin

    Trevor
    #259219

    Unfortunately, with the current version of our plugin, that may well not work (as we use JavaScript to use the query parameters, even though they look like a normal form query string, they are not processed as such.

    Are you able to send me a live link/URL to your search page so I can take a look? One that I can see this in action?

    Please note that we are now closed for the weekend and any replies may be delayed until we open at 10AM (UK time) on Monday (I will try to reply before then).

    Anonymous
    #259223
    This reply has been marked as private.
    Trevor
    #259369
    This reply has been marked as private.
    Anonymous
    #259371

    I figured that out over the weekend!!!! Thank you soooooooo much, Trevor!!!! If you click in the menu under Adopt a Cat, Dog, etc. now it filters them based on the animal type. You’ve been so helpful and responsive. I appreciate it so much!!! 😀

    Trevor
    #259373

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

Viewing 6 posts – 1 through 6 (of 6 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.