I want to rewrite url parameters values on checkbox click, similar to LinkedIn Advance search.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type='text/javascript'>
$(document).ready(function () {
$('input[type=checkbox]').click(function (e) {
var seasoning = jQuery.map($(':checkbox[id=seasoning\\[\\]]:checked'), function (n, i) {return n.value;}).join(',');
window.location ='example.com?seasoning='+seasoning;
});
});
</script>
<h3>Filter recepies:</h3>
<div>
<p>Select vegetables</p>
<label><input type="checkbox" id="vegetables[]" value="potato"> Potato</label><br>
<label><input type="checkbox" id="vegetables[]" value="onion"> Onion</label><br>
<label><input type="checkbox" id="vegetables[]" value="tomato"> Tomato</label><br>
</div>
<div>
<p>Select seasoning</p>
<label><input type="checkbox" id="seasoning[]" value="salt"> Salt</label><br>
<label><input type="checkbox" id="seasoning[]" value="pepper"> Pepper</label><br>
<label><input type="checkbox" id="seasoning[]" value="chilli"> Chilli Flakes</label><br>
</div>
My Desired Result
Click1: when I click Potato from vegitable my URL should look like
example.com?vegitables=potato
Click2: when I click Onion from vegitable my URL should look like
example.com?vegitables=potato,onion
Click3: when I click salt from seasoning my URL should look like
example.com?vegitables=potato,onion&seasoning=salt
Click4: when I click pepper from seasoning my URL should look like
example.com?vegitables=potato,onion&seasoning=salt,pepper