Remove URL parameter if no checkboxes are selected

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Remove URL parameter if no checkboxes are selected



I'm attempting to setup some basic filtering on a page using the following script. However, if the user unchecks all boxes, the page refreshes with a blank areas parameter. How can I check against this happening and therefore remove the areas query in the URL if no checkboxes are selected?


areas


areas



Thanks.


(function($)
$('#filters').on('change', 'input[type="checkbox"]', function()

// vars
var $ul = $(this).closest('ul'),
vals = ;

$ul.find('input:checked').each(function()
vals.push( $(this).val() );
);

vals = vals.join(",");

window.location.replace('<?php echo home_url('casestudies'); ?>?areas=' + vals );
console.log(vals);



);
)(jQuery);




1 Answer
1



Add this code before vals = vals.join(",");


if( vals.length == 0 )
window.location.replace('<?php echo home_url('casestudies'); ?>');





Just needed to add an additional if statement around the original declaration and it worked perfectly. Thanks!
– James Kindred
Aug 7 at 20:26







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard