I have jQuery that gets parameters from form select options and adds it to the URL for search. But at the moment my JS removes the old stuff and replaces with new always. Here's the current one:
$("#year").change(function() {
var path = $(location).attr('href').split('?', 1);;
var year = $(this).val();
var search = path + '?year=' + year;
if ($(this).val() != '') {
window.open(search, '_self');
}
});
$("#type").change(function() {
var path = $(location).attr('href').split('?', 1);;
var type = $(this).val();
var search = path + '?type=' + type;
if ($(this).val()) {
window.open(search, '_self');
}
});
So if user selects from another option the would be: www.domain.com/search?type=something or www.domain.com/search?year=2011
But what I would like to do is that the user could choose both parameters. So the URL could be www.domain.com/search?type=something&year=2011 but I'm not sure how to do it.
I tried something but then it always added new parameters to the end and the URL ended up being like this: www.domain.com/search?type=something&year=2011&type=something&year=2011&type=something&year=2011
Thanks for help!