Based on the question below and example , I wanted to achieved that result based on the clicked box with the name and value to be added on the url.example of that is based on the checked box the url output https://test.com/searchnewdata?Year=2020,2019,2018&Model=EcoSport,Edge.
Basic JS basis
$(document).ready(function(){
$("#btnSearch").click(function(){
//var url="http://example.com/results?choice=choice2&choice=choice4"
var url="http://example.com/results?choice=";
var flag=false;
$("input:checkbox[name=choice]:checked").each(function(){
if(!flag)
{
url=url+$(this).val();
flag=true;// To trace if first query string added
}
else
{
url=url+"&choice="+$(this).val();
}
});
alert(url);
});
});
HTML CODE
<form name="search_something" action=/results method="get">
<text>Year</text>
<input type="checkbox" name="Year" value="2019">2019<br>
<input type="checkbox" name="Year" value="2018">2018<br>
<input type="checkbox" name="Year" value="2017">2017<br>
<input type="checkbox" name="Year" value="2016">2016<p>
<text>Model</text>
<input type="checkbox" name="Make" value="choice1">BMW<br>
<input type="checkbox" name="Make" value="choice2">Ecosport<br>
<input type="checkbox" name="Make" value="choice3">Acura<br>
<input type="checkbox" name="Make" value="choice4">Edge<p>
<input type="button" id="btnSearch" value="Search">
</form>
Desired Result for example based on the checked box.
https://test.com/searchnewdata?Year=2020,2019,2018&Model=EcoSport,Edge