Forums › Forums › Search & Filter Pro › Set default radio button with URL
- This topic has 5 replies, 2 voices, and was last updated 6 years, 2 months ago by
Trevor.
-
Anonymous(Private) September 11, 2020 at 4:13 pm #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(Private) September 11, 2020 at 5:21 pm #259219Unfortunately, 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(Private) September 14, 2020 at 5:22 pm #259371I 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!!! 😀
-
AuthorPosts