I have some check box to get Brand name and size, i want to display value for selected check box in url box like
www.xyz.com?brands=P,Q,R&Size=2,3
I've this code that shows,
www.xyz.com?brands=P&brands=Q&brands=R&Size=2&Size=3
JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$('input[type="checkbox"]').on('change', function(e) {
var data = [],
loc = $('<a>', {
href: window.location
})[0];
$('input[type="checkbox"]').each(function() {
if (this.checked) {
data.push(this.name + '=' + this.value);
}
});
data = data.join('&');
$.post('/ajax-post-url/', data);
if (history.pushState) {
history.pushState(null, null, loc.pathname + '?' + data);
}
});
</script>
HTML
<div class="pane">
<div class="ele">
<input type="checkbox" value="X" name="Brand">
<label>Brand 1</label>
<input type="checkbox" value="Y" name="Brand">
<label>Brand 2</label>
<input type="checkbox" value="Z" name="Brand">
<label>Brand 3</label>
<input type="checkbox" value="1" name="Size">
<label>Size 1</label>
<input type="checkbox" value="2" name="Size">
<label>Size 2</label>
<input type="checkbox" value="3" name="Size">
<label>Size 3</label>
</div>
</div>