There is a url of type / catalog / f / execution = filter% 201, filter% 202; switch-type = type1, type2, type3 /

and checkbox types

<input type="checkbox" class="f[21][]" value="393" name="f[21][]" id="393" value-url="фильтр 1"> 

You need to go through the url and put checked all checkboxes in which the value-url matches the parameters in the URL.

  • You do not match - a space in the value-url="фильтр 1" - Igor
  • Space was removed when creating a question. In the real urle, it exists - Alexander Gontar
  • Well, in which of these actions do you have difficulty? - Igor
  • I do not know how to do it all right. whether url should be on an array or url should be checked as a string for each checkbox. I do not want to write crookedly and how to do it well does not occur to me. - Alexander Gontar

1 answer 1

You can do it like this

 $(function() { var link = decodeURIComponent(location.href); var filter = {execution: link.replace(/.+execution\=([^;]+)\;?.*/, '$1').split(','), switchtype: link.replace(/.+switch\-type\=([^;]+)\;?.*/, '$1').split(',')}; for(var i = 0; i < filter.execution.length; i++){ $('input[value-url="'+filter.execution[i]+'"]').attr('checked', ''); }; }); 
  • YES, but it will only work on a certain execution parameter. And I have them dynamic depending on the selected filter - Alexander Gontar
  • @AlexanderGontar, I did not understand. This will work for all filters that you specify in the url - Yuri
  • execution, switch-type are the names of the filters in which the parameters are selected. But these filters can be many. Now your version works only on execution. - Alexander Gontar
  • @AlexanderGontar, what's stopping you from applying this option to a lot of filters? - Yuri
  • filters are created through the admin panel of the site. I do not know how to choose all the possible filter options - Alexander Gontar