I have a form with different features
<form name="filter" action= method="get">
<input type=checkbox name="color" value="red">Red<br>
<input type=checkbox name="color" value="blue">Blue<br>
<input type=checkbox name="color" value="white">White<br>
<input type=checkbox name="size" value="small">Small<br>
<input type=checkbox name="size" value="medium">Medium<br>
<input type=checkbox name="size" value="large">Large<br>
...
</form>
I need to generate a link with url like this:
if red is checked > http://example.com/products?color=red
if red and blue are checked > http://example.com/products?color=red,blue
if red blue and small are checked > http://example.com/products?color=red,blue&size=small
And after, in the link page, mark as checked the input in link
in http://example.com/products?color=red > red input is checked
Thanks for help!
UPDATE
This is a script to generate url by input value, but doesn't work with different input name JSFIDDLE
<span class="link"></span>
$("input[type=checkbox]").on("change", function(){
    var arr = []
    $(":checkbox").each(function(){
       if($(this).is(":checked")){
         arr.push($(this).val())
       }
    })
    var vals = arr.join(",")
  var name = $(this).attr('name')
    var str = "http://example.com/products?" + name + "=" + vals
    console.log(str);
  if (vals.length > 0) {
    $('.link').html($('<a>', {
      href: str,
      text: str
    }));
  } else {
    $('.link').html('');
  }  
})
 
    